Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: new span StatusCode is being exported to collector with wrong value in v0.13.0 #1736

Closed
blumamir opened this issue Dec 9, 2020 · 1 comment · Fixed by #1751
Closed
Assignees
Labels
bug Something isn't working

Comments

@blumamir
Copy link
Member

blumamir commented Dec 9, 2020

What version of OpenTelemetry are you using?

v0.13.0

I might be missing something, but in v0.13.0, CanonicalCode changed to StatusCode in this PR, but in collector exporter the new enum is assigned to the proto status field without any proper format transformation here.
We are copying an enum looking like this:

export enum StatusCode {
  OK = 0,
  UNSET = 1,
  ERROR = 2,
}

Into an enum looking like this:

  enum StatusCode {
    STATUS_CODE_OK                  = 0;
    STATUS_CODE_CANCELLED           = 1;
    STATUS_CODE_UNKNOWN_ERROR       = 2;
    STATUS_CODE_INVALID_ARGUMENT    = 3;
    STATUS_CODE_DEADLINE_EXCEEDED   = 4;
    STATUS_CODE_NOT_FOUND           = 5;
    STATUS_CODE_ALREADY_EXISTS      = 6;
    STATUS_CODE_PERMISSION_DENIED   = 7;
    STATUS_CODE_RESOURCE_EXHAUSTED  = 8;
    STATUS_CODE_FAILED_PRECONDITION = 9;
    STATUS_CODE_ABORTED             = 10;
    STATUS_CODE_OUT_OF_RANGE        = 11;
    STATUS_CODE_UNIMPLEMENTED       = 12;
    STATUS_CODE_INTERNAL_ERROR      = 13;
    STATUS_CODE_UNAVAILABLE         = 14;
    STATUS_CODE_DATA_LOSS           = 15;
    STATUS_CODE_UNAUTHENTICATED     = 16;
  };

By the way, the new field in the proto for the new status code format is:

  enum StatusCode {
    STATUS_CODE_UNSET               = 0;
    STATUS_CODE_OK                  = 1;
    STATUS_CODE_ERROR               = 2;
  };

Which is also not aligned with the new format (OK is 0 in JS and 1 in proto, and UNSET is 1 in JS and 0 on proto).
I believe this field needs to be transformed with a function toCollectorStatus similar to the other fields in the proto, and be set to the proper, new field in the protobuf ( StatusCode code = 3 instead of DeprecatedStatusCode deprecated_code = 1 [deprecated=true])

In additional, I'm not sure about compatibility to old collectors and to plugins dependent on old versions of the @opentelemetry/api but exporting with @opentelemetry/[email protected] (all the plugins in the contrib repo, for example)

@blumamir blumamir added the bug Something isn't working label Dec 9, 2020
@blumamir
Copy link
Member Author

Example of the bug in exporter/[email protected]:

"use strict";

const opentelemetry = require("@opentelemetry/api");
const {
  BasicTracerProvider,
  ConsoleSpanExporter,
  SimpleSpanProcessor,
} = require("@opentelemetry/tracing");
// const { CollectorTraceExporter } = require("@opentelemetry/exporter-collector");
const {
  CollectorTraceExporter,
} = require("@opentelemetry/exporter-collector-grpc");
// const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector-proto');

const exporter = new CollectorTraceExporter({
  serviceName: "basic-service",
});

const provider = new BasicTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.register();

const tracer = opentelemetry.trace.getTracer("example-collector-exporter-node");

const parentSpan = tracer.startSpan("main");
parentSpan.end();

// give some time before it is closed
setTimeout(() => {
  // flush and close the connection.
  exporter.shutdown();
}, 2000);

shows up in collector v0.16.0 with

exporters:
  logging:
    loglevel: debug

as:

Span #0
    Trace ID       : 3bfa30d26e0988db2a40f2ff231818ce
    Parent ID      : 
    ID             : 6af40bbf384e45da
    Name           : main
    Kind           : SPAN_KIND_INTERNAL
    Start time     : 2020-12-13 16:36:16.358481664 +0200 IST
    End time       : 2020-12-13 16:36:16.358669568 +0200 IST
    Status code    : STATUS_CODE_ERROR     <== <== <== <== <== <== <== <== <== <== <== 
    Status message : 

This is because it's being exported with the wrong status code (1 == UNSET) which interpreted in the collector as STATUS_CODE_CANCELLED as explained above:

{
  traceId: '3bfa30d26e0988db2a40f2ff231818ce',
  parentId: undefined,
  name: 'main',
  id: '6af40bbf384e45da',
  kind: 0,
  timestamp: 1607870176358482,
  duration: 188,
  attributes: {},
  status: { code: 1 },
  events: []
}

This is a new bug introduced in v0.13.0 of the opentelemetry-js.

@blumamir blumamir changed the title New StatusCode and exporter collector Bug: new span StatusCode is being exported to collector with wrong value in v0.13.0 Dec 13, 2020
@obecny obecny self-assigned this Dec 14, 2020
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this issue Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants