-
Notifications
You must be signed in to change notification settings - Fork 5
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
add jaeger tracing #3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really interested in your thoughts on Jaeger, got any screenshots?
I think the UI needs some work but it gets the job done. I think i enjoyed using datadog more. heres a quick vid https://www.loom.com/share/160c2fb03e834cc8bb75f1345c99146c |
app/__init__.py
Outdated
import os | ||
|
||
if os.environ.get("OTEL_SERVICE_NAME"): | ||
import opentelemetry.instrumentation.auto_instrumentation.sitecustomize as autotrace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this certainly works. You can also do the pre-setup too like you had and just call this at the end. Example:
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
resource = Resource(attributes={
SERVICE_NAME: "fastApiDockerPoetry-2"
})
provider = TracerProvider(resource=resource)
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
trace.set_tracer_provider(provider)
import opentelemetry.instrumentation.auto_instrumentation.sitecustomize as autotrace
The real power of doing that is that you can do different things based on your BaseSettings
bindings instead of only using environment variables.
For example, you might want to disable exports like in a local environment (relevant if you're using something like Datadog or don't wan to run Jaeger):
settings = get_settings()
if settings.otel_export_enabled:
trace_provider.add_span_processor(
BatchSpanProcessor(
OTLPSpanExporter(endpoint=f"http://{settings.otel_agent}:4317", insecure=True, timeout=5)
)
)
else:
logger.info("OpenTelemetry trace/span exports are disabled")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
youre right I'm creating an inconsistent pattern. Ill add these to BaseSettings and merge
OTEL_SERVICE_NAME: fastApiDockerPoetry
OTEL_METRICS_EXPORTER: none
OTEL_TRACES_EXPORTER: "otlp"
OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger:4317
What an understatement!!! A lot of work!! |
No description provided.