Skip to content

How to disable tracing for some sql request once psycopg2 integration is setup ? #706

@r4mbo7

Description

@r4mbo7

Hi !

I want to integrate OpenTelemetry in a large project that use a postgresql database.

If I setup the psycopg2 integration like this in a tracing.py module...

from opentelemetry import trace
from opentelemetry.ext import psycopg2
from opentelemetry.sdk.trace import TracerProvider

trace.set_tracer_provider(TracerProvider())

psycopg2.trace_integration()

... then I "magically" got spans emitted for every single database request made in project.

But I do not want a span for each request. In fact there is few requests that are valuables among all of them. I want to save few cpu, networks, logs and storage by avoiding to emit spans for most of these requests.

Can I still use opentelemtry psycopg2 integration ?
Should I use the start_as_current_span context for the few requests that I'm interested in ? If so, can I retrieve the attributes that were added in the span by the psycopg2 integration, i.e. can I re-use the psycopg2 integration subpackage ?

Many thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions