Alana Storm
Alana Storm

Reputation: 166086

How to Serialize an OpenTelemetry Javascript Span

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.

Upvotes: 0

Views: 1187

Answers (1)

Srikanth Chekuri
Srikanth Chekuri

Reputation: 2274

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.

Upvotes: 1

Related Questions