signalfx / splunk-otel-python

Splunk distribution of OpenTelemetry Python
Apache License 2.0
35 stars 11 forks source link

Django Auto Instrumentation Not Working #249

Closed tjohander-splunk closed 7 months ago

tjohander-splunk commented 2 years ago

I'm trying to get Auto Instrumentation working for a sample Django application. My project repo is here. Details of my project configuration and bootstrapping process is detailed in the repo's README.md

The output of pip freeze > requirements.txt is but for reference, here is what's been installed in the venv:

asgiref==3.5.2
backoff==1.11.1
Deprecated==1.2.13
Django==4.0.6
googleapis-common-protos==1.56.4
grpcio==1.47.0
opentelemetry-api==1.11.1
opentelemetry-exporter-jaeger-thrift==1.11.1
opentelemetry-exporter-otlp-proto-grpc==1.11.1
opentelemetry-instrumentation==0.30b1
opentelemetry-instrumentation-aws-lambda==0.30b1
opentelemetry-instrumentation-dbapi==0.30b1
opentelemetry-instrumentation-django==0.30b1
opentelemetry-instrumentation-grpc==0.30b1
opentelemetry-instrumentation-logging==0.30b1
opentelemetry-instrumentation-sqlite3==0.30b1
opentelemetry-instrumentation-urllib==0.30b1
opentelemetry-instrumentation-wsgi==0.30b1
opentelemetry-propagator-aws-xray==1.0.1
opentelemetry-propagator-b3==1.11.1
opentelemetry-proto==1.11.1
opentelemetry-sdk==1.11.1
opentelemetry-semantic-conventions==0.30b1
opentelemetry-util-http==0.30b1
protobuf==3.20.1
six==1.16.0
splunk-opentelemetry==1.6.0
sqlparse==0.4.2
thrift==0.16.0
typing_extensions==4.3.0
wrapt==1.14.1

And in my manage.py I've tried both adding the call DjangoInstrumentor().instrument(), as well as bootstrapping the application with splunk-py-trace python3 ./manage.py runserver. I am not using wsgi for this local example.

I've run the collector with both the docker-compose based container for the Collector as well as this command to get an instance of the collector running with the defaults:

docker run --rm -e SPLUNK_ACCESS_TOKEN=<my-token> -e SPLUNK_REALM=us1 \
    -p 13133:13133 -p 14250:14250 -p 14268:14268 -p 4317:4317 -p 6060:6060 \
    -p 7276:7276 -p 8888:8888 -p 9080:9080 -p 9411:9411 -p 9943:9943 \
    --name otelcol quay.io/signalfx/splunk-otel-collector:latest
owais commented 1 year ago

I tried but wasn't able to reproduce. Here is what I did:

  1. cloned the linked repo
  2. created virtualenv with python -m venv venv
  3. activated venv with source venv/bin/activate
  4. installed dependencies pip install -r reqiurements.txt
  5. Set the following env vars:
    • export OTEL_SERVICE_NAME='django-example-server'
    • export OTEL_RESOURCE_ATTRIBUTES='deployment.environment=tj-devlab'
    • export DJANGO_SETTINGS_MODULE='instrumentation_example.settings'
  6. Started Django server with: splunk-py-trace python3 ./manage.py runserver --noreload
  7. Sent a request using curl with: curl http://localhost:8000

Otel collector logged the following spans:

2022-09-22T13:44:00.982+0530    info    TracesExporter  {"kind": "exporter", "data_type": "traces", "name": "logging", "#spans": 2}
2022-09-22T13:44:00.982+0530    info    ResourceSpans #0
Resource SchemaURL:
Resource attributes:
     -> telemetry.sdk.language: STRING(python)
     -> telemetry.sdk.name: STRING(opentelemetry)
     -> telemetry.sdk.version: STRING(1.11.1)
     -> deployment.environment: STRING(tj-devlab)
     -> service.name: STRING(django-example-server)
     -> telemetry.auto.version: STRING(0.30b1)
     -> splunk.distro.version: STRING(1.6.0)
ScopeSpans #0
ScopeSpans SchemaURL:
InstrumentationScope opentelemetry.instrumentation.sqlite3 0.30b1
Span #0
    Trace ID       : bb2dbb48a3d169e8b51e2c762406feaa
    Parent ID      :
    ID             : 2a3ee74d537ea239
    Name           : SELECT
    Kind           : SPAN_KIND_CLIENT
    Start time     : 2022-09-22 08:13:56.367716 +0000 UTC
    End time       : 2022-09-22 08:13:56.367902 +0000 UTC
    Status code    : STATUS_CODE_UNSET
    Status message :
Attributes:
     -> db.system: STRING(sqlite)
     -> db.name: STRING()
     -> db.statement: STRING(
            SELECT name, type FROM sqlite_master
            WHERE type in ('table', 'view') AND NOT name='sqlite_sequence'
            ORDER BY name)
ScopeSpans #1
ScopeSpans SchemaURL:
InstrumentationScope opentelemetry.instrumentation.django 0.30b1
Span #0
    Trace ID       : 9f27260e6a1fb1fd32fd70e84a663d0c
    Parent ID      :
    ID             : 7d5fb72775466b3d
    Name           :
    Kind           : SPAN_KIND_SERVER
    Start time     : 2022-09-22 08:14:00.115277 +0000 UTC
    End time       : 2022-09-22 08:14:00.11972 +0000 UTC
    Status code    : STATUS_CODE_UNSET
    Status message :
Attributes:
     -> http.method: STRING(GET)
     -> http.server_name: STRING(1.0.0.127.in-addr.arpa)
     -> http.scheme: STRING(http)
     -> net.host.port: INT(8000)
     -> http.host: STRING(localhost:8000)
     -> http.url: STRING(http://localhost:8000/)
     -> net.peer.ip: STRING(127.0.0.1)
     -> http.user_agent: STRING(curl/7.79.1)
     -> http.flavor: STRING(1.1)
     -> http.status_code: INT(200)
    {"kind": "exporter", "data_type": "traces", "name": "logging"}
owais commented 1 year ago

My otel collector config:

receivers:
  otlp:
    protocols:
        grpc:
            endpoint: 0.0.0.0:4317
        http:
            endpoint: 0.0.0.0:55681

exporters:
  logging:
      loglevel: debug

service:
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [logging]
pmcollins commented 7 months ago

Closing as this is quite old. If it's is still an issue please let us know.