Skip to content

Commit

Permalink
Update tracing setup (#1228)
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-baseten authored Nov 5, 2024
1 parent 2c599bd commit d9e1c01
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions truss/templates/server/common/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
logger = logging.getLogger(__name__)

ATTR_NAME_DURATION = "duration_sec"
# "New" Jaeger exporter.
OTEL_EXPORTER_OTLP_ENDPOINT = "OTEL_EXPORTER_OTLP_ENDPOINT"
# "Old" Honeycomb exporter. We might want to temporarily export to both, but
# eventually remove this one.
OTEL_EXPORTER_OTLP_ENDPOINT_LEGACY = "OTEL_EXPORTER_OTLP_ENDPOINT_LEGACY"
# Writing trace data to a file is only intended for testing / debugging.
OTEL_TRACING_NDJSON_FILE = "OTEL_TRACING_NDJSON_FILE"
# Exporting trace data to a public honeycomb instance (not our cluster collector)
Expand Down Expand Up @@ -72,19 +68,15 @@ def get_truss_tracer(secrets: secrets_resolver.Secrets, config) -> trace.Tracer:

span_processors: List[sdk_trace.SpanProcessor] = []
if otlp_endpoint := os.getenv(OTEL_EXPORTER_OTLP_ENDPOINT):
logger.info(f"Exporting trace data to {OTEL_EXPORTER_OTLP_ENDPOINT}.")
otlp_exporter = oltp_exporter.OTLPSpanExporter(endpoint=otlp_endpoint)
otlp_processor = sdk_trace.export.BatchSpanProcessor(otlp_exporter)
span_processors.append(otlp_processor)

if otlp_endpoint := os.getenv(OTEL_EXPORTER_OTLP_ENDPOINT_LEGACY):
logger.info(f"Exporting trace data to {OTEL_EXPORTER_OTLP_ENDPOINT_LEGACY}.")
if enable_tracing_data:
logger.info(f"Exporting trace data to {OTEL_EXPORTER_OTLP_ENDPOINT}.")
otlp_exporter = oltp_exporter.OTLPSpanExporter(endpoint=otlp_endpoint)
otlp_processor = sdk_trace.export.BatchSpanProcessor(otlp_exporter)
span_processors.append(otlp_processor)

if tracing_log_file := os.getenv(OTEL_TRACING_NDJSON_FILE):
logger.info(f"Exporting trace data to file `{tracing_log_file}`.")
if enable_tracing_data:
logger.info(f"Exporting trace data to file `{tracing_log_file}`.")
json_file_exporter = JSONFileExporter(pathlib.Path(tracing_log_file))
file_processor = sdk_trace.export.SimpleSpanProcessor(json_file_exporter)
span_processors.append(file_processor)
Expand All @@ -106,7 +98,7 @@ def get_truss_tracer(secrets: secrets_resolver.Secrets, config) -> trace.Tracer:

if span_processors and enable_tracing_data:
logger.info("Instantiating truss tracer.")
resource = resources.Resource.create({resources.SERVICE_NAME: "TrussServer"})
resource = resources.Resource.create({resources.SERVICE_NAME: "truss-server"})
trace_provider = sdk_trace.TracerProvider(resource=resource)
for sp in span_processors:
trace_provider.add_span_processor(sp)
Expand Down

0 comments on commit d9e1c01

Please sign in to comment.