Skip to content

Django + opentelemetry-ext-dbapi creates separate mysql traces for middleware #1160

@ebrake

Description

@ebrake

When using opentelemetry-ext-dbapi with django (using mysqlclient here), mysql component traces are being created with separate trace ids. This generates loads of traces which should instead be spans of the primary trace/request.

The separate mysql traces all seem to be from middleware (auth, sessions, cookies, custom, etc.) as well as system (migrations, content types, SHOW FULL TABLES, etc) ... the middleware traces should, at least, be contained as spans of the default trace. Can't filter them out, either.

e.g.

from opentelemetry import trace
from opentelemetry.instrumentation.dbapi import trace_integration
from opentelemetry.instrumentation.django import DjangoInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
from opentelemetry.sdk.trace.sampling import TraceIdRatioBased
import MySQLdb
# Instrument django
DjangoInstrumentor().instrument()
# Sample 1 in every 100 traces
sampler = TraceIdRatioBased(1/100)
# Set the sampler onto the global tracer provider
trace.set_tracer_provider(TracerProvider(sampler=sampler))
trace.get_tracer_provider().add_span_processor(BatchExportSpanProcessor())
# Instrument mysql
trace_integration(MySQLdb, "connect", "mysql", "sql")

=> 1 trace of component: http
=> multiple traces with different trace ids of component: mysql

Related to: #659

Since we have varying opinions about this, should it be made configurable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions