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

feat: Add OpenTelemetry tracing #5295

Closed
wants to merge 23 commits into from
Closed

feat: Add OpenTelemetry tracing #5295

wants to merge 23 commits into from

Conversation

nlgotz
Copy link
Contributor

@nlgotz nlgotz commented Feb 15, 2024

Closes #4783

What's Changed

  • Adds in OpenTelemetry libraries for:
    • Django
    • Celery
    • Postgres
    • MySQL
    • Redis
  • Adds in tooling to export Telemetry to OTLP or console
  • Adds in docker compose files to setup Grafana, Loki, Mimir/Prometheus, and Tempo to send data to as a demo

Screenshots

image

Postgres Select inside a celery job:
image

TODO

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • Attached Screenshots, Payload Example
  • Unit, Integration Tests
  • Documentation Updates (when adding/changing features)
  • Example Plugin Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

@nlgotz nlgotz marked this pull request as ready for review February 20, 2024 20:13
@nlgotz nlgotz changed the title feat: initial work on otel tracing feat: Add OpenTelemetry tracing Feb 23, 2024
pyproject.toml Outdated
Comment on lines 220 to 231
[tool.poetry.group.observability.dependencies]
opentelemetry-api = "^1.22.0"
opentelemetry-sdk = "^1.22.0"
opentelemetry-exporter-otlp = "^1.22.0"
opentelemetry-instrumentation-django = "^0.43b0"
opentelemetry-instrumentation-celery = "^0.43b0"
opentelemetry-instrumentation-psycopg2 = "^0.43b0"
opentelemetry-instrumentation-dbapi = "^0.43b0"
opentelemetry-instrumentation-redis = "^0.43b0"
opentelemetry-instrumentation-logging = "^0.43b0"
opentelemetry-instrumentation-mysqlclient = "^0.43b0"
opentelemetry-instrumentation-wsgi = "^0.43b0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these actually development-only dependencies? I would have thought they'd need to be added to the main project dependencies instead of in this group.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it to make it a requirement. That got missed since the docker container includes everything for dev


OpenTelemetry logs, traces, and metrics are not exposed by default. To enable this, the `OTEL_PYTHON_DJANGO_INSTRUMENT` setting should be set to `True`. This will do two things:

- Logs will be exposed in the OpenTelemetry format and include the Trace ID, Span ID, and Resource attributes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposed where/how?

OpenTelemetry logs, traces, and metrics are not exposed by default. To enable this, the `OTEL_PYTHON_DJANGO_INSTRUMENT` setting should be set to `True`. This will do two things:

- Logs will be exposed in the OpenTelemetry format and include the Trace ID, Span ID, and Resource attributes.
- Metrics and Traces will be logged to console.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide sample output of how things differ when this feature is enabled?


---

### OTEL_PYTHON_DJANGO_INSTRUMENT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entries in this file are alphabetically sorted, IIRC - would be good to stick with that convention.


Default: `False`

Environment Variable: `OTEL_PYTHON_DJANGO_INSTRUMENT`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these OpenTelemetry conventions, or should the environment variables all be prefixed with NAUTOBOT_ for self-consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are OpenTelemetry conventions but I had to set them up manually since some of the OpenTelemetry auto-tooling doesn't work with the nautobot-server command. Possibly with some of the changes in #5310, the auto-tooling will work. I'll have to explore/test that

nautobot/core/runner/runner.py Outdated Show resolved Hide resolved
development/dev.env Outdated Show resolved Hide resolved
@nlgotz nlgotz closed this Jun 18, 2024
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

Successfully merging this pull request may close these issues.

2 participants