0

Question: Is there any code that can take an OpenTelemetry JS span object (as received by an exporter) and transform it into an object that has just its telemetry data and not internal implementation details?

That is -- if I have an exporter like this

    class FileSpanExporter {
      constructor() {
        this.stream = fs.createWriteStream('/tmp/telemetry.log', {flag:'a'})
      }
      export(spans, resultCallback) {
          this.stream.write(JSON.stringify(spans))
          if(resultCallback) {
            return resultCallback({ code: core.ExportResultCode.SUCCESS });
          }
      }
    }

The span(s) that get written to the the log include data I'd consider telemetry data

    "attributes": {
      "express.name": "query",
      "express.type": "middleware"
    },
    // ...
    "endTime": [
      1622658683,
      606307380
    ],
    // ...    

but also includes data that's implementation details

    "_spanProcessor": {
      "_spanProcessors": [
        {
          "_exporter": {
        // ... way more data snipped ...

Does the open telemetry javascript code have any way to serialize a span to get just its telemetry data? Or is that something that's the responsibility of the end-user-programmer to decide which data they are/aren't interested in before exporting. All I've been able to find so far is the span.context() method, which returns only the context information, but not other pertinent data.

Alana Storm
  • 164,128
  • 91
  • 395
  • 599

1 Answers1

1

You are probably looking for something similar to this https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-tracing/src/export/ConsoleSpanExporter.ts. This is explicitly designed for debugging purposes and not a great choice for actual applications.

Srikanth Chekuri
  • 1,944
  • 1
  • 9
  • 19
  • +1 -- thank you for the information. The functionality in the `_exportInfo` method of that class is the example sort of thing I'm looking for, but I'm looking for whether there's a public/supported API for doing this, or if it's up to each exporter to do it's own serializing before sending the data on. – Alana Storm Jun 02 '21 at 23:35
  • It is upto the each exporter to encode and serialize. – Srikanth Chekuri Jun 03 '21 at 03:49
  • Have a look at the Jaeger and Zipkin exporters as well. They both have their own serialising functions to convert a ReadableSpan into their native representations. – paganwinter Dec 09 '21 at 16:02