Enable telemetry in your service
Add two lines at startup before you create yourServiceHost:
Python
otel_config() uses the injected OTEL_ENDPOINT and room/session environment to send telemetry to MeshAgent Studio.
Example: Weather Toolkit with custom instrumentation
The example adds custom spans around validation, the external HTTP call, and response parsing. It also adds logs and metrics.Custom spans
Use spans to track specific operations inside a trace. This example records:execute.weather-toolkit.get_weather, which MeshAgent creates for the overall tool callvalidate_inputfor city and units validationfetch_weather_apifor the outbound HTTP request, including attributes such ashttp.url,http.method,http.status_code, andhttp.response_sizeparse_responsefor the final response shaping step
Python
Custom logs
otel_config() sets up an OTEL logging handler so normal logging calls are captured too.
Python
Custom metrics
You can also add counters and histograms to track trends over time.Python
Deploy the sample
You can deploy this toolkit as a service and invokeget_weather() from Studio or the CLI.
Step 1: Package and deploy the room service
Package the sample with ameshagent.yaml file and a container image that MeshAgent can run. For the general deployment flow, see Deploy Services with MeshAgent.
This example uses a MeshAgent runtime image plus a lightweight code image. The default YAML points at the public python-docs-examples image so you can run the docs example without building your own image first.
Project structure:
observability/ folder.
Step 1a: Build a Docker image
Create a scratch Dockerfile and copy the files you want to run:bash
Step 1b: Define the service
Create ameshagent.yaml file that references:
- Runtime image: The MeshAgent Python SDK image with all dependencies
- Code mount: Your code-only image mounted at /src
- Command path: Points to your sample’s specific location
- Your code image contains
/observability/observability.py - It’s mounted at
/srcin the runtime container - The command runs
python /src/observability/observability.py
us-central1-docker.pkg.dev/meshagent-public/images/python-docs-examples so you can test this example immediately without building your own image first. Replace this with your own image tag when deploying your code.
Step 1c: Deploy the service
From the directory that containsmeshagent.yaml:
Step 2: Invoke the tool
Once the service is deployed, invoke the tool from MeshAgent Studio or the CLI. You can also invoke the tool using the MeshAgent CLI:bash
View telemetry
In MeshAgent Studio, you can inspect the telemetry from this example in both the Session view and the Developer Console. After you invoke the weather tool, the Traces tab should show a tree like:Next Steps
- Observability: understand the built-in telemetry model and where to inspect it in MeshAgent Studio
- Agents: understand how agents work in MeshAgent and start building your first one
- Tools and Toolkits: learn how tools are discovered, shared, and called inside a MeshAgent room
- Deploy Services with MeshAgent: deploy instrumented agents and tools as room or project services