SyZero.OpenTelemetry
1.1.9
dotnet add package SyZero.OpenTelemetry --version 1.1.9
NuGet\Install-Package SyZero.OpenTelemetry -Version 1.1.9
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SyZero.OpenTelemetry" Version="1.1.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.OpenTelemetry" Version="1.1.9" />
<PackageReference Include="SyZero.OpenTelemetry" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SyZero.OpenTelemetry --version 1.1.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero.OpenTelemetry, 1.1.9"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SyZero.OpenTelemetry@1.1.9
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SyZero.OpenTelemetry&version=1.1.9
#tool nuget:?package=SyZero.OpenTelemetry&version=1.1.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SyZero.OpenTelemetry
SyZero 的 OpenTelemetry 扩展,负责注册 ASP.NET Core / HttpClient 的 tracing、metrics 和 logging,并按配置挂接 OTLP exporter。
安装
dotnet add package SyZero.OpenTelemetry
快速开始
{
"SyZero": {
"Name": "order-service"
},
"OpenTelemetry": {
"OtlpUrl": "http://localhost:4317",
"EnableTracing": true,
"EnableMetrics": true,
"EnableLogging": true,
"AspNetCorePathPrefixes": [ "/api" ],
"HttpClientPathPrefixes": [ "/api" ],
"ActivitySources": [ "OrderService" ],
"Meters": [ "OrderService" ]
}
}
var builder = WebApplication.CreateBuilder(args);
builder.AddSyZero();
builder.Services.AddSyZeroOpenTelemetry();
也可以通过代码覆盖配置:
builder.Services.AddSyZeroOpenTelemetry(options =>
{
options.ServiceName = "order-service";
options.OtlpUrl = "http://localhost:4318";
options.OtlpProtocol = OpenTelemetry.Exporter.OtlpExportProtocol.HttpProtobuf;
options.HttpClientPathPrefixes = Array.Empty<string>(); // 采集所有出站 HTTP 请求
});
可用重载
services.AddSyZeroOpenTelemetry();
services.AddSyZeroOpenTelemetry(configuration);
services.AddSyZeroOpenTelemetry(options => { });
services.AddSyZeroOpenTelemetry(options => { }, configuration);
配置说明
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
ServiceName |
string |
SyZero:Name 或入口程序集名 |
资源中的服务名 |
ServiceVersion |
string |
入口程序集版本 | 资源中的服务版本 |
OtlpUrl |
string |
null |
OTLP 导出地址;未配置时不会注册 OTLP exporter |
OtlpProtocol |
OtlpExportProtocol |
Grpc |
OTLP 协议 |
EnableTracing |
bool |
true |
是否启用 tracing |
EnableMetrics |
bool |
true |
是否启用 metrics |
EnableLogging |
bool |
true |
是否启用 logging |
ActivitySources |
string[] |
空数组 | 需要额外订阅的 ActivitySource 名称 |
Meters |
string[] |
空数组 | 需要额外订阅的 Meter 名称;内置会额外监听 Microsoft.AspNetCore.Hosting、Microsoft.AspNetCore.Server.Kestrel、Microsoft.AspNetCore.Routing、System.Net.Http |
AspNetCorePathPrefixes |
string[] |
["/api"] |
需要采集的入站请求路径前缀 |
HttpClientPathPrefixes |
string[] |
空数组 | 需要采集的出站请求路径前缀;为空表示不过滤 |
说明
AddSource("*")/AddMeter("*")不会自动订阅所有自定义 source/meter,因此这里改成显式配置名称。- metrics 默认通过监听 .NET 8+ 的内置 meter 名称来采集 HTTP / Kestrel / Routing 指标,而不是依赖当前目标框架下不可用的 metrics instrumentation 扩展。
- 如果没有配置
OtlpUrl,模块仍然会完成 OpenTelemetry 注册,但不会主动创建 OTLP 导出连接。 AspNetCorePathPrefixes会同时支持/api和/api/...这种匹配,避免只识别带尾斜杠的路径。
许可证
MIT License - 详见 LICENSE
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.11.2)
- OpenTelemetry.Extensions.Hosting (>= 1.11.2)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.11.1)
- OpenTelemetry.Instrumentation.Http (>= 1.11.0)
- SyZero (>= 1.1.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.9 | 99 | 4/19/2026 |
| 1.1.9-dev.2 | 47 | 4/19/2026 |
| 1.1.9-dev.1 | 58 | 4/17/2026 |
| 1.1.8 | 87 | 4/17/2026 |
| 1.1.6 | 88 | 4/17/2026 |
| 1.1.6-dev.1 | 42 | 4/17/2026 |
| 1.1.5 | 100 | 4/13/2026 |
| 1.1.5-dev.3 | 58 | 4/13/2026 |
| 1.1.5-dev.2 | 61 | 2/11/2026 |
| 1.1.5-dev.1 | 60 | 1/29/2026 |
| 1.1.4 | 109 | 1/2/2026 |
| 1.1.4-dev.2 | 69 | 1/2/2026 |
| 1.1.4-dev.1 | 64 | 12/30/2025 |
| 1.1.3 | 108 | 12/30/2025 |
| 1.1.3-dev.6 | 65 | 12/30/2025 |
| 1.0.0 | 91 | 4/17/2026 |