Skip to content

How to use Slonik with OpenTelemetry? #500

Closed Answered by gajus
gajus asked this question in Q&A
Discussion options

You must be logged in to vote

Here is an example of a simple interceptor that adds traceparent to queries:

import { context, defaultTextMapSetter } from '@opentelemetry/api';
import { W3CTraceContextPropagator } from '@opentelemetry/core';

// ...

interceptors.push({
  transformQuery: (queryContext, query) => {
    const propagator = new W3CTraceContextPropagator();

    const comments = {};

    propagator.inject(context.active(), comments, defaultTextMapSetter);

    if ('traceparent' in comments) {
      return {
        ...query,
        sql: `${query.sql} /* traceparent='${comments.traceparent}' */`,
      };
    }

    return query;
  },
});

Related question https://stackoverflow.com/questions/76831794/how-get-…

Replies: 1 comment 1 reply

Comment options

gajus
Aug 3, 2023
Maintainer Author

You must be logged in to vote
1 reply
@gajus
Comment options

gajus Aug 3, 2023
Maintainer Author

Answer selected by gajus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant