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

Missing parent link #533

Open
mafad-pandora opened this issue Nov 10, 2022 · 0 comments
Open

Missing parent link #533

mafad-pandora opened this issue Nov 10, 2022 · 0 comments

Comments

@mafad-pandora
Copy link

When multiple sequential calls to tracer.local are made, then only the span of the first tracer.local is linked to the parent span, while the spans of subsequent calls have no parent at all.

See the example program below, where I would expect a parent "GET" span with 3 child spans "my_db_operation 1", "my_db_operation 2" and "my_db_operation 3".

Instead the actual result there is a parent "GET" span with 1 child span "my_db_operation 1", then two more spans that have no parent: "my_db_operation 2" and "my_db_operation 3".

Screenshot 2022-11-10 at 16 32 27

Screenshot 2022-11-10 at 16 32 41

const express = require('express')
const app = express()
const port = 3000

const { Tracer, ExplicitContext, BatchRecorder, jsonEncoder } = require("zipkin");
const { HttpLogger } = require("zipkin-transport-http");
const CLSContext = require('zipkin-context-cls');
const zipkinMiddleware = require("zipkin-instrumentation-express").expressMiddleware;
const tracer = new Tracer({
  ctxImpl: new CLSContext('zipkin'), // implicit in-process context
  recorder: new BatchRecorder({
    logger: new HttpLogger({
      endpoint: 'http://jaeger-collector:9411/api/v2/spans',
      jsonEncoder: jsonEncoder.JSON_V2,
    }),
  }),
  localServiceName: "example-app",
});
app.use(zipkinMiddleware({ tracer }));

function my_db_operation(x) {
  console.log(`My DB operation ${x}`)
  ms = Math.floor(Math.random() * 600) + 50;
  return new Promise(resolve => setTimeout(resolve, ms));
}

app.get('/', async (req, res) => {
  await tracer.local("my_db_operation 1", () => my_db_operation(1));
  await tracer.local("my_db_operation 2", () => my_db_operation(2));
  await tracer.local("my_db_operation 3", () => my_db_operation(3));
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Maartens example app started and is listening on port ${port}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant