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

add jaeger tracing #3

Merged
merged 7 commits into from
Jun 5, 2023
Merged

add jaeger tracing #3

merged 7 commits into from
Jun 5, 2023

Conversation

rannysweis
Copy link
Owner

No description provided.

@rannysweis rannysweis marked this pull request as draft May 26, 2023 01:54
@rannysweis rannysweis marked this pull request as ready for review May 30, 2023 16:24
Copy link
Collaborator

@phillipuniverse phillipuniverse left a 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?

Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@rannysweis
Copy link
Owner Author

rannysweis commented Jun 2, 2023

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
Comment on lines 1 to 4
import os

if os.environ.get("OTEL_SERVICE_NAME"):
import opentelemetry.instrumentation.auto_instrumentation.sitecustomize as autotrace
Copy link
Collaborator

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")

Copy link
Owner Author

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

@phillipuniverse
Copy link
Collaborator

I think the UI needs some work but it gets the job done.

What an understatement!!! A lot of work!!

@rannysweis rannysweis merged commit 7e0e163 into master Jun 5, 2023
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.

3 participants