Skip to main content
MeshAgent already gives you logs, traces, metrics, session data, and developer logs in MeshAgent Studio. Use this page when you want to add your own spans, logs, and metrics inside a custom Python service or room-connected toolkit. For the built-in observability model first, see Observability.

Enable telemetry in your process

Call otel_config() once at process startup:
Python
When this code runs inside MeshAgent, 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 call
  • validate_input for city and units validation
  • fetch_weather_api for the outbound HTTP request, including attributes such as http.url, http.method, http.status_code, and http.response_size
  • parse_response for the final response shaping step
This gives you finer-grained visibility inside the spans MeshAgent already creates. Pattern:
Python
These spans appear in the room’s Traces tab.

Custom logs

otel_config() sets up an OTEL logging handler so normal logging calls are captured too.
Python
These logs appear in the room’s Logs tab.

Custom metrics

You can also add counters and histograms to track trends over time.
Python
These metrics appear in the room’s Metrics tab.

Deploy the sample

You can run this toolkit locally with meshagent room connect, deploy it as a service, and invoke get_weather() from Studio or the CLI.

Run it locally

During development, run the toolkit with meshagent room connect so MeshAgent provides the room token, room name, LLM proxy credentials, and telemetry environment:
bash

Step 1: Package and deploy the room service

Package the sample with a meshagent.yaml file and a container image that MeshAgent can run. For the general deployment flow, see Service YAML. 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:
If you are building a single tool, you only need the observability/ folder.

Step 1a: Build a Docker image

Create a scratch Dockerfile and copy the files you want to run:
Build and push the image:
bash

Step 1b: Define the service

Create a meshagent.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
  • Participant token: Injects MESHAGENT_TOKEN for the room-connected toolkit process
Path mapping:
  • Your code image contains /observability/observability.py
  • It’s mounted at /src in the runtime container
  • The command runs python /src/observability/observability.py
The default YAML in the docs uses 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 contains meshagent.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:
Logs and metrics appear under their respective tabs.

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
  • Service YAML: write service manifests for instrumented agents and tools