diff --git a/libs/arcade-serve/arcade_serve/core/components.py b/libs/arcade-serve/arcade_serve/core/components.py index f28885bf..25465008 100644 --- a/libs/arcade-serve/arcade_serve/core/components.py +++ b/libs/arcade-serve/arcade_serve/core/components.py @@ -73,7 +73,8 @@ class CallToolComponent(WorkerComponent): current_span.set_attribute("tool_name", str(call_tool_request.tool.name)) current_span.set_attribute("toolkit_version", str(call_tool_request.tool.version)) current_span.set_attribute("toolkit_name", str(call_tool_request.tool.toolkit)) - current_span.set_attribute("environment", self.worker.environment) + if hasattr(self.worker, "environment"): + current_span.set_attribute("environment", self.worker.environment) return await self.worker.call_tool(call_tool_request) diff --git a/libs/arcade-serve/arcade_serve/fastapi/telemetry.py b/libs/arcade-serve/arcade_serve/fastapi/telemetry.py index 1be9998d..d77793a4 100644 --- a/libs/arcade-serve/arcade_serve/fastapi/telemetry.py +++ b/libs/arcade-serve/arcade_serve/fastapi/telemetry.py @@ -1,14 +1,17 @@ import logging import os import urllib.parse -from typing import Optional +from typing import Literal, Optional from fastapi import FastAPI from opentelemetry import _logs, trace from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter +from opentelemetry.instrumentation.aiohttp_client import AioHttpClientInstrumentor from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor +from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor +from opentelemetry.instrumentation.requests import RequestsInstrumentor from opentelemetry.metrics import Meter, get_meter_provider, set_meter_provider from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler from opentelemetry.sdk._logs.export import BatchLogRecordProcessor @@ -21,7 +24,7 @@ from opentelemetry.semconv._incubating.attributes import deployment_attributes from opentelemetry.semconv.attributes import service_attributes EXCLUDED_URLS = "/worker/health" -EXCLUDED_SPANS = ["send", "receive"] +EXCLUDED_SPANS: list[Literal["send", "receive"]] = ["send", "receive"] class ShutdownError(Exception): @@ -59,6 +62,9 @@ class OTELHandler: FastAPIInstrumentor().instrument_app( app, excluded_urls=EXCLUDED_URLS, exclude_spans=EXCLUDED_SPANS ) + HTTPXClientInstrumentor()._instrument(tracer_provider=self._tracer_provider) + AioHttpClientInstrumentor()._instrument(tracer_provider=self._tracer_provider) + RequestsInstrumentor()._instrument(tracer_provider=self._tracer_provider) def _init_tracer(self) -> None: self._tracer_provider = TracerProvider(resource=self.resource) diff --git a/libs/arcade-serve/pyproject.toml b/libs/arcade-serve/pyproject.toml index 7092f2dc..e945326c 100644 --- a/libs/arcade-serve/pyproject.toml +++ b/libs/arcade-serve/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "arcade-serve" -version = "3.2.0" +version = "3.2.1" description = "Arcade Serve - Serving infrastructure for Arcade tools and workers" readme = "README.md" license = {text = "MIT"} @@ -27,6 +27,10 @@ dependencies = [ "opentelemetry-instrumentation-fastapi==0.49b2", "opentelemetry-exporter-otlp-proto-http==1.28.2", "opentelemetry-exporter-otlp-proto-common==1.28.2", + "opentelemetry-instrumentation-httpx==0.49b2", + "opentelemetry-instrumentation-aiohttp-client==0.49b2", + "opentelemetry-instrumentation-requests==0.49b2", + "aiohttp>=3.0.0,<4.0.0", ] [project.optional-dependencies]