-
Notifications
You must be signed in to change notification settings - Fork 593
Add OTel exporter for weave + example config #1827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| general: | ||
| telemetry: | ||
| tracing: | ||
| weave_otel: | ||
| _type: weave_otel | ||
| project: "nat-demo" | ||
| entity: "your-team-name" | ||
|
|
||
| function_groups: | ||
| calculator: | ||
| _type: calculator | ||
|
|
||
| functions: | ||
| current_datetime: | ||
| _type: current_datetime | ||
|
|
||
| llms: | ||
| nim_llm: | ||
| _type: nim | ||
| model_name: meta/llama-3.1-70b-instruct | ||
| temperature: 0.0 | ||
| max_tokens: 1024 | ||
|
|
||
| workflow: | ||
| _type: react_agent | ||
| tool_names: [calculator, current_datetime] | ||
| llm_name: nim_llm | ||
| verbose: true | ||
| parse_agent_response_max_retries: 3 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
|
|
||
| import logging | ||
| import os | ||
| from collections.abc import AsyncGenerator | ||
|
|
||
| from pydantic import Field | ||
|
|
||
|
|
@@ -209,6 +210,49 @@ async def galileo_telemetry_exporter(config: GalileoTelemetryExporter, builder: | |
| ) | ||
|
|
||
|
|
||
| class WeaveOtelTelemetryExporter(BatchConfigMixin, TelemetryExporterBaseConfig, name="weave_otel"): | ||
| """A telemetry exporter to transmit traces to Weights & Biases Weave via OTel.""" | ||
|
|
||
| endpoint: str = Field( | ||
| description="The W&B Weave OTel endpoint", | ||
| default="https://trace.wandb.ai/otel/v1/traces", | ||
| ) | ||
| api_key: SerializableSecretStr = Field(description="The W&B API key", | ||
| default_factory=lambda: SerializableSecretStr("")) | ||
| project: str = Field(description="The W&B project name.") | ||
| entity: str = Field(description="The W&B username or team name.") | ||
|
|
||
|
|
||
| @register_telemetry_exporter(config_type=WeaveOtelTelemetryExporter) | ||
| async def weave_otel_telemetry_exporter( | ||
| config: WeaveOtelTelemetryExporter, builder: Builder, | ||
| ) -> AsyncGenerator["OTLPSpanAdapterExporter", None]: | ||
| """Create a Weave OTel telemetry exporter.""" | ||
|
Comment on lines
+227
to
+230
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify the reported lint error on this file.
ruff check --select F821 packages/nvidia_nat_opentelemetry/src/nat/plugins/opentelemetry/register.pyRepository: NVIDIA/NeMo-Agent-Toolkit Length of output: 648 🏁 Script executed: #!/bin/bash
# Find where OTLPSpanAdapterExporter is defined
rg -n "class OTLPSpanAdapterExporter" --type pyRepository: NVIDIA/NeMo-Agent-Toolkit Length of output: 237 🏁 Script executed: #!/bin/bash
# Check the current imports and structure of the file around the problematic section
head -230 packages/nvidia_nat_opentelemetry/src/nat/plugins/opentelemetry/register.py | tail -50Repository: NVIDIA/NeMo-Agent-Toolkit Length of output: 2318 🏁 Script executed: #!/bin/bash
# Check the imports at the top of the register.py file
head -50 packages/nvidia_nat_opentelemetry/src/nat/plugins/opentelemetry/register.pyRepository: NVIDIA/NeMo-Agent-Toolkit Length of output: 2392 🏁 Script executed: #!/bin/bash
# Verify the full function context and check if there are any existing TYPE_CHECKING imports
grep -n "TYPE_CHECKING\|from typing\|from collections" packages/nvidia_nat_opentelemetry/src/nat/plugins/opentelemetry/register.py | head -20Repository: NVIDIA/NeMo-Agent-Toolkit Length of output: 114 🏁 Script executed: #!/bin/bash
# Check if there are TYPE_CHECKING imports elsewhere in the codebase for similar patterns
rg -n "TYPE_CHECKING" packages/nvidia_nat_opentelemetry/src/nat/plugins/opentelemetry/ --type pyRepository: NVIDIA/NeMo-Agent-Toolkit Length of output: 51 🏁 Script executed: #!/bin/bash
# Verify the exact line numbers in the function to understand the context better
sed -n '225,260p' packages/nvidia_nat_opentelemetry/src/nat/plugins/opentelemetry/register.pyRepository: NVIDIA/NeMo-Agent-Toolkit Length of output: 1484 Add TYPE_CHECKING import to resolve Ruff F821 for forward reference in return annotation. Line 229 has a forward reference Add a module-level import guard to satisfy the type checker: Suggested fix+from typing import TYPE_CHECKING
+
+if TYPE_CHECKING:
+ from nat.plugins.opentelemetry import OTLPSpanAdapterExporter
+
async def weave_otel_telemetry_exporter(
config: WeaveOtelTelemetryExporter, builder: Builder,
) -> AsyncGenerator["OTLPSpanAdapterExporter", None]:The local import inside the function (line 231) can remain for backward compatibility with runtime behavior. 🧰 Tools🪛 Ruff (0.15.7)[error] 229-229: Undefined name (F821) 🤖 Prompt for AI Agents |
||
|
|
||
| from nat.plugins.opentelemetry import OTLPSpanAdapterExporter | ||
|
|
||
| api_key = get_secret_value(config.api_key) if config.api_key else os.environ.get("WANDB_API_KEY") | ||
| if not api_key: | ||
| raise ValueError("API key is required for Weave (set api_key or WANDB_API_KEY env var)") | ||
|
|
||
| headers = {"wandb-api-key": api_key} | ||
| resource_attributes = { | ||
| "wandb.project": config.project, | ||
| "wandb.entity": config.entity, | ||
| } | ||
|
|
||
| yield OTLPSpanAdapterExporter( | ||
| endpoint=config.endpoint, | ||
| headers=headers, | ||
| resource_attributes=resource_attributes, | ||
| batch_size=config.batch_size, | ||
| flush_interval=config.flush_interval, | ||
| max_queue_size=config.max_queue_size, | ||
| drop_on_overflow=config.drop_on_overflow, | ||
| shutdown_timeout=config.shutdown_timeout, | ||
| ) | ||
|
|
||
|
|
||
| class DBNLTelemetryExporter(BatchConfigMixin, TelemetryExporterBaseConfig, name="dbnl"): | ||
| """A telemetry exporter to transmit traces to DBNL.""" | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You added this configuration, but the README wasn't updated.
examples/observability/simple_calculator_observability/README.mdThe documentation should also be updated accordingly to reflect that W&B Weave has an OTel exporter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! It should be updated now. I put the OTel guide in the existing Weave docs but happy to place it into a separate one if that's preferable