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

Fix opentelemetry adapter #510

Merged
merged 6 commits into from
Nov 23, 2024
Merged

Conversation

dineshyv
Copy link
Contributor

What does this PR do?

This PR fixes some of the issues with our telemetry setup to enable logs to be delivered to opentelemetry and jaeger. Main fixes

  1. Updates the open telemetry provider to use the latest oltp exports instead of deprected ones.
  2. Adds a tracing middleware, which injects traces into each HTTP request that the server recieves and this is going to be the root trace. Previously, we did this in the create_dynamic_route method, which is actually not the actual exectuion flow, but more of a config and this causes the traces to end prematurely. Through middleware, we plugin the trace start and end at the right location.
  3. We manage our own methods to create traces and spans and this does not fit well with Opentelemetry SDK since it does not support provide a way to take in traces and spans that are already created. it expects us to use the SDK to create them. For now, I have a hacky approach of just maintaining a map from our internal telemetry objects to the open telemetry specfic ones. This is not the ideal solution. I will explore other ways to get around this issue. for now, to have something that works, i am going to keep this as is.

Addresses: #509

Test Plan

  • Start Jaeger
docker run -d --name jaeger \
  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  -p 5775:5775 \
  -p 6831:6831 \
  -p 6832:6832 \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 14250:14250 \
  -p 14268:14268 \
  -p 14269:14269 \
  -p 9411:9411 \
  jaegertracing/all-in-one:1.47
  • Start llama stack
    llama stack run /Users/dineshyv/.llama/distributions/llamastack-together/together-run.yaml
  • Run a RAG app
    PYTHONPATH=. python -m examples.agents.rag_with_memory_bank localhost 5000
  • Go to Jaeger UI to see traces
Screenshot 2024-11-22 at 5 58 25 PM

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 23, 2024
@dineshyv dineshyv changed the title Dineshyv/telemetry with opentelemetry Fix opentelemetry adapter Nov 23, 2024
@@ -282,6 +211,19 @@ async def endpoint(request: Request, **kwargs):
return endpoint


class TracingMiddleware:
Copy link
Contributor

Choose a reason for hiding this comment

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

🤟

@@ -8,5 +8,5 @@


class OpenTelemetryConfig(BaseModel):
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 add a sample_run_config() here while you are at it. it will be useful some day.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

agent_port=self.config.jaeger_port,
provider = TracerProvider(resource=resource)
trace.set_tracer_provider(provider)
otlp_exporter = OTLPSpanExporter(
Copy link
Contributor

@ashwinb ashwinb Nov 23, 2024

Choose a reason for hiding this comment

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

I think it would be really useful to dump what this entity is ending on the wire to Jaeger as we talked about. If we can elide it, we reduce our dependency on all of these libraries too. The protocol is open.

Copy link
Contributor

@ashwinb ashwinb left a comment

Choose a reason for hiding this comment

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

stamp-approved :)

@dineshyv dineshyv merged commit 501e7c9 into main Nov 23, 2024
2 checks passed
@dineshyv dineshyv deleted the dineshyv/telemetry-with-opentelemetry branch November 23, 2024 02:18
SLR722 pushed a commit that referenced this pull request Nov 27, 2024
# What does this PR do?

This PR fixes some of the issues with our telemetry setup to enable logs
to be delivered to opentelemetry and jaeger. Main fixes
1) Updates the open telemetry provider to use the latest oltp exports
instead of deprected ones.
2) Adds a tracing middleware, which injects traces into each HTTP
request that the server recieves and this is going to be the root trace.
Previously, we did this in the create_dynamic_route method, which is
actually not the actual exectuion flow, but more of a config and this
causes the traces to end prematurely. Through middleware, we plugin the
trace start and end at the right location.
3) We manage our own methods to create traces and spans and this does
not fit well with Opentelemetry SDK since it does not support provide a
way to take in traces and spans that are already created. it expects us
to use the SDK to create them. For now, I have a hacky approach of just
maintaining a map from our internal telemetry objects to the open
telemetry specfic ones. This is not the ideal solution. I will explore
other ways to get around this issue. for now, to have something that
works, i am going to keep this as is.

Addresses: #509
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants