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

Auto instrumentation of express app is not sending exception event in trace #2146

Open
legendary-acp opened this issue Apr 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@legendary-acp
Copy link

What version of OpenTelemetry are you using?

"@opentelemetry/api": "1.8.0"
"@opentelemetry/auto-instrumentations-node": "0.44.0"

What version of Node are you using?

v20.12.2

What did you do?

Ran a simple express app which raises exception.

const express = require('express');
const app = express();


function ErrorGenerator(a, b) {
    if (b === 0) {
        throw new Error('Division by zero error');
    }
    return a / b;
}


app.get('/', (req, res) => {
    const result = ErrorGenerator(10, 0);
    console.log('Result:', result);
    res.send("Here is results of highest computed maths");
});

app.use((err, req, res, next) => {
    console.error('An error occurred:', err.message);
    res.status(400).send('Bad Request: ' + err.message);
    next(err);
  });

const port = 6002;
app.listen(port, () => {
    console.log(`Server is running on port ${port}`);
});

What did you expect to see?

On hitting the endpoint get a span with exception in event array. Somewhat similar to this:

{
  traceId: '7d57f374b49081a2c46aee1b9334d1c7',
  parentId: undefined,
  traceState: undefined,
  name: 'GET',
  id: 'dfdebec418911ea9',
  kind: 2,
  timestamp: 1714033150562000,
  duration: 3011281.152,
  attributes: {
    'http.url': 'http://169.254.169.254/computeMetadata/v1/instance',
    'http.method': 'GET',
    'http.target': '/computeMetadata/v1/instance',
    'net.peer.name': '169.254.169.254',
    'http.host': '169.254.169.254:80',
    'http.error_name': 'Error',
    'http.error_message': 'socket hang up'
  },
  status: { code: 2, message: 'socket hang up' },
  events: [
    {
      name: 'exception',
      attributes: {
        'exception.type': 'ECONNRESET',
        'exception.message': 'socket hang up',
        'exception.stacktrace': 'Error: socket hang up\n' +
          '    at Socket.socketCloseListener (node:_http_client:473:25)\n' +
          '    at Socket.emit (node:events:530:35)\n' +
          '    at TCP.<anonymous> (node:net:337:12)\n' +
          '    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)'
      },
      time: [ 1714033153, 573273845 ],
      droppedAttributesCount: 0
    }
  ],
  links: []
}

What did you see instead?

{
  traceId: 'f2a2854b4e599d5abb83960e4904fb79',
  parentId: undefined,
  traceState: undefined,
  name: 'GET /',
  id: '46e1fb4811ce2415',
  kind: 1,
  timestamp: 1714033162279000,
  duration: 9807.383,
  attributes: {
    'http.url': 'http://localhost:6002/',
    'http.host': 'localhost:6002',
    'net.host.name': 'localhost',
    'http.method': 'GET',
    'http.scheme': 'http',
    'http.target': '/',
    'http.user_agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15',
    'http.flavor': '1.1',
    'net.transport': 'ip_tcp',
    'net.host.ip': '::1',
    'net.host.port': 6002,
    'net.peer.ip': '::1',
    'net.peer.port': 50140,
    'http.status_code': 400,
    'http.status_text': 'BAD REQUEST',
    'http.route': '/'
  },
  status: { code: 0 },
  events: [],
  links: []
}
@legendary-acp legendary-acp added the bug Something isn't working label Apr 25, 2024
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

No branches or pull requests

1 participant