Skip to content

Commit

Permalink
🚧 added jaeger in agency
Browse files Browse the repository at this point in the history
  • Loading branch information
rathijitpapon committed Jun 27, 2024
1 parent f04e3de commit 09810ec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
4 changes: 3 additions & 1 deletion agency/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ TRACING__SENTRY_DSN=
# TRACING__ENABLE_TRACING=
# TRACING__ENVIRONMENT=
# TRACING__PHOENIX_API=
# TRACING__PHOENIX_PROJECT_NAME=
# TRACING__PROJECT_NAME=
# TRACING__SERVIVE_NAME=
# TRACING__JAEGER_ENDPOINT=

# GROQ API Configuration
GROQ__API_KEY=
Expand Down
4 changes: 3 additions & 1 deletion agency/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ class WandbSettings(BaseSettings):

class TracingSettings(BaseSettings):
sentry_dsn: SecretStr
jaeger_endpoint: str = "http://127.0.0.1:4317"
enable_tracing: bool = False
environment: str = "development"
phoenix_api: str = "http://127.0.0.1:6006/v1/traces"
phoenix_project_name: str = "Curieo Search Agency"
project_name: str = "Curieo Search"
service_name: str = "agency-service"


class GroqSettings(BaseSettings):
Expand Down
38 changes: 31 additions & 7 deletions agency/app/tracing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
import sentry_sdk
from openinference.instrumentation.llama_index import LlamaIndexInstrumentor
from openinference.semconv.resource import ResourceAttributes
from opentelemetry import trace
from opentelemetry import trace as trace_api
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.instrumentation.grpc import GrpcAioInstrumentorServer
from opentelemetry.instrumentation.llamaindex import (
LlamaIndexInstrumentor as OpentelemetryLlamaIndexInstrumentor,
)
from opentelemetry.propagate import set_global_textmap
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, SimpleSpanProcessor
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
from sentry_sdk.integrations.asyncio import AsyncioIntegration
from sentry_sdk.integrations.grpc import GRPCIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
Expand All @@ -17,6 +25,26 @@

def setup_tracing(settings: TracingSettings) -> None:
if settings.environment == "production":
# jaeger opentelemetry tracing
resource = Resource(
attributes={
ResourceAttributes.PROJECT_NAME: settings.project_name,
"service.name": settings.service_name,
},
)
trace.set_tracer_provider(TracerProvider(resource=resource))
trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(
OTLPSpanExporter(
endpoint=settings.jaeger_endpoint,
)
)
)
set_global_textmap(TraceContextTextMapPropagator())
GrpcAioInstrumentorServer().instrument()
OpentelemetryLlamaIndexInstrumentor().instrument()

# sentry tracing
sentry_sdk.init(
dsn=settings.sentry_dsn.get_secret_value(),
enable_tracing=settings.enable_tracing,
Expand All @@ -27,11 +55,7 @@ def setup_tracing(settings: TracingSettings) -> None:
],
)

resource = Resource(
attributes={
ResourceAttributes.PROJECT_NAME: settings.phoenix_project_name,
},
)
# phoenix tracing
tracer_provider = trace_sdk.TracerProvider(resource=resource)
span_exporter = OTLPSpanExporter(endpoint=settings.phoenix_api)
span_processor = SimpleSpanProcessor(span_exporter=span_exporter)
Expand Down

0 comments on commit 09810ec

Please sign in to comment.