XiansAi.Otel.Lib
1.0.1
dotnet add package XiansAi.Otel.Lib --version 1.0.1
NuGet\Install-Package XiansAi.Otel.Lib -Version 1.0.1
<PackageReference Include="XiansAi.Otel.Lib" Version="1.0.1" />
<PackageVersion Include="XiansAi.Otel.Lib" Version="1.0.1" />
<PackageReference Include="XiansAi.Otel.Lib" />
paket add XiansAi.Otel.Lib --version 1.0.1
#r "nuget: XiansAi.Otel.Lib, 1.0.1"
#:package XiansAi.Otel.Lib@1.0.1
#addin nuget:?package=XiansAi.Otel.Lib&version=1.0.1
#tool nuget:?package=XiansAi.Otel.Lib&version=1.0.1
XiansAi.Otel.Lib
XiansAi.Otel.Lib initializes OpenTelemetry (traces, metrics, logs) for agents/worker-style .NET processes and exports them via OTLP.
Enablement is endpoint-driven (OPENTELEMETRY_ENDPOINT for traces/metrics, optional OPENTELEMETRY_LOGS_ENDPOINT for logs).
It is designed to work with XiansAi agents but can be used by any .NET app that wants OTEL-compatible exports.
Install
dotnet add package XiansAi.Otel.Lib
Automatically captured (out of the box)
- Traces: outgoing HTTP via HttpClient (spans + trace propagation)
- Metrics: runtime + HttpClient metrics
- Logs:
Microsoft.Extensions.Logginglogs via OTLP (when you use theILoggerFactoryreturned byTelemetryBuilder.InitializeAgent(...)) - Temporal traces: captured if
Temporalio.Extensions.OpenTelemetryis used by the host and the Temporal interceptor is enabled (XiansAi.Lib wires this; generic apps must enable it themselves) - Your own spans: captured if your code emits
Activityspans and you include yourActivitySourcename/pattern inadditionalActivitySources
GenAI sensitive content events (optional)
If you want Semantic Kernel to include prompt/response content in gen_ai.* events (e.g. gen_ai.event.content), set:
OPENTELEMETRY_GENAI_SENSITIVE=true
This is off by default because it can capture sensitive data.
Example 1 — Add to a XiansAi agent
In your agent’s Program.cs (after creating AgentTeam), initialize OTEL with tenant-aware service name:
using XiansAi.Flow;
using XiansAi.Otel;
using Microsoft.Extensions.Logging;
var agent = new AgentTeam("News Agent");
var loggerFactory = TelemetryBuilder.InitializeAgent(
tenantId: AgentContext.TenantId,
serviceName: agent.Name,
enableLogs: true);
if (loggerFactory != null)
{
Globals.LogFactory = loggerFactory;
}
await agent.RunAsync();
Example 2 — Add to a generic .NET app
In any console/worker app:
using XiansAi.Otel;
TelemetryBuilder.InitializeAgent(
tenantId: "tenant-01",
serviceName: "abcd.company01",
additionalActivitySources: new[] { "Sample.SomePackage*" },
additionalMeters: new[] { "Sample.SomePackage*" },
enableLogs: true);
Example (manual spans via ActivitySource)
If you want spans for your own code (e.g. in a package like Sample.SomePackage.*), create an ActivitySource and start activities:
using System.Diagnostics;
namespace Sample.SomePackage;
public static class Telemetry
{
public static readonly ActivitySource Source = new("Sample.SomePackage");
}
public static class Example
{
public static void FuncB()
{
using var span = Telemetry.Source.StartActivity("FuncB");
// do work...
}
public static void FuncA()
{
using var span = Telemetry.Source.StartActivity("FuncA");
FuncB();
}
}
To export these spans, pass your source name/pattern via additionalActivitySources to TelemetryBuilder.InitializeAgent(...).
Instrumentation sources/meters configuration
This library ships a default list via an embedded JSON: Defaults/otel-defaults.json.
To add more sources/meters, pass additionalActivitySources / additionalMeters to TelemetryBuilder.InitializeAgent(...).
Package metadata
- Package ID:
XiansAi.Otel.Lib - Target framework:
net9.0 - NuGet package includes
README.mdandLICENSE
Release and publish
Publishing is automated with GitHub Actions.
- Trigger: push a tag in the format
v*(for examplev1.2.3) - Version source: tag value without the
vprefix - Feed:
https://api.nuget.org/v3/index.json - Credential: repository secret
NUGET_API_KEY
The resulting artifact pushed to NuGet is:
XiansAi.Otel.Lib.<version>.nupkg
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Microsoft.Extensions.Logging (>= 10.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Logging.Console (>= 10.0.1)
- OpenTelemetry (>= 1.14.0)
- OpenTelemetry.Api (>= 1.14.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.14.0)
- OpenTelemetry.Instrumentation.Http (>= 1.14.0)
- OpenTelemetry.Instrumentation.Runtime (>= 1.14.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.