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

http plugin: no span attributes when http.get() throws #1255

Closed
blumamir opened this issue Jun 29, 2020 · 0 comments · Fixed by #2349
Closed

http plugin: no span attributes when http.get() throws #1255

blumamir opened this issue Jun 29, 2020 · 0 comments · Fixed by #2349
Labels
bug Something isn't working

Comments

@blumamir
Copy link
Member

What version of OpenTelemetry are you using?

v0.9.0

What version of Node are you using?

v13.11.0

What did you do?

instrumented http module with @opentelemetry/plugin-http. then called http.get(url, options, cb) with invalid header which caused the function to throw an exception.

If possible, provide a recipe for reproducing the error.

import { NodeTracerProvider } from "@opentelemetry/node";
import { SimpleSpanProcessor } from '@opentelemetry/tracing';
import { JaegerExporter } from '@opentelemetry/exporter-jaeger';

const provider = new NodeTracerProvider({
    logger: console
});

const exporter = new JaegerExporter({
    logger: console,
    serviceName: 'http-out-debug'
});
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.register();

import * as http from 'http';
http.get('http://www.google.com', {
    headers: {
        cookie: undefined, // <============ this make http.get throw
    }
},
(res) => {

    res.setEncoding('utf8');
    let rawData = '';
    res.on('data', (chunk) => { rawData += chunk; });
    res.on('end', () => {
        console.log('got back data');
    });

});

What did you expect to see?

Http span with error, and relevant attributes (at least http.url).

What did you see instead?

Http span with error, but http.url and other request attributes missing in the span.

Span {
  attributes: {
    component: 'http',
    'http.error_name': 'TypeError',
    'http.error_message': 'Invalid value "undefined" for header "cookie"'
  },
  links: [],
  events: [],
  status: { code: 2, message: 'Invalid value "undefined" for header "cookie"' },
  endTime: [ 1593439010, 94328504 ],
  _ended: true,
  _duration: [ 0, 3152474 ],
  name: 'GET /',
  spanContext: {
    traceId: '414aa171b3c5cd00539a0d86ea7ab5b8',
    spanId: '6b1e1761ee041018',
    traceFlags: 1,
    traceState: undefined
  },
  parentSpanId: undefined,
  kind: 2,
  startTime: [ 1593439010, 91176030 ],
  resource: Resource {
    labels: {
      'telemetry.sdk.language': 'nodejs',
      'telemetry.sdk.name': 'opentelemetry',
      'telemetry.sdk.version': '0.9.0'
    }
  }
}

Additional context

When there are a lot of requests, and some requests fails due to bad header, the trace is missing important attributes which can be used to debug the issue (like http.url)
This is because getOutgoingRequestAttributes is called after the original patched function call.
I suggest to move getOutgoingRequestAttributes before original.apply, so span will contain url and other attributes if original.apply throw.

@blumamir blumamir added the bug Something isn't working label Jun 29, 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.

1 participant