This guide explains how to configure a .NET app using the .NET OpenTelemetry SDK to send telemetry data to Axiom.
program.cs
below.dotnet.csproj
file in your project with the following:
dotnet.csproj
file is important for defining your project’s settings, including target framework, nullable reference types, and package references. It informs the .NET SDK and build tools about the components and configurations your project requires.
program.cs
is the core of the .NET application. It uses ASP.NET to create a simple web server. The server has an endpoint /rolldice
that returns a random number, simulating a basic API.
tracing.cs
file sets up the OpenTelemetry instrumentation. It configures the OTLP (OpenTelemetry Protocol) exporters for traces and initializes the ASP.NET SDK with automatic instrumentation capabilities.
serviceName
variable with the name of the service you want to trace. This is used for identifying and categorizing trace data, particularly in systems with multiple services.Replace API_TOKEN
with the Axiom API token you have generated. For added security, store the API token in an environment variable.Replace DATASET_NAME
with the name of the Axiom dataset where you want to send data.Replace AXIOM_DOMAIN
with api.axiom.co
if your organization uses the US region, and with api.eu.axiom.co
if your organization uses the EU region. For more information, see Regions.appsettings.development.json
. Ensure your Axiom API token and dataset name are correctly set in tracing.cs
.
appsettings.json
for production settings. Ensure your Axiom API token and dataset name are correctly set in tracing.cs
.
dotnet run
. Your application starts and you can interact with it by sending requests to the /rolldice
endpoint.
8080
, your application is accessible locally at http://localhost:8080/rolldice
. This URL will direct your requests to the /rolldice
endpoint of your server running on your local machine.
ActivitySource
to create activities (spans) for tracing specific operations within your application.TracerProvider
in your program.cs
or startup configuration, which automatically captures telemetry data from supported libraries.
API_TOKEN
with the Axiom API token you have generated. For added security, store the API token in an environment variable.Replace DATASET_NAME
with the name of the Axiom dataset where you want to send data.Replace AXIOM_DOMAIN
with api.axiom.co
if your organization uses the US region, and with api.eu.axiom.co
if your organization uses the EU region. For more information, see Regions.Field Category | Field Name | Description |
---|---|---|
General Trace Information | ||
_rowId | Unique identifier for each row in the trace data. | |
_sysTime | System timestamp when the trace data was recorded. | |
_time | Timestamp when the actual event being traced occurred. | |
trace_id | Unique identifier for the entire trace. | |
span_id | Unique identifier for the span within the trace. | |
parent_span_id | Unique identifier for the parent span within the trace. | |
HTTP Attributes | ||
attributes.http.request.method | HTTP method used for the request. | |
attributes.http.response.status_code | HTTP status code returned in response. | |
attributes.http.route | Route accessed during the HTTP request. | |
attributes.url.path | Path component of the URL accessed. | |
attributes.url.scheme | Scheme component of the URL accessed. | |
attributes.server.address | Address of the server handling the request. | |
attributes.server.port | Port number on the server handling the request. | |
Network Attributes | ||
attributes.network.protocol.version | Version of the network protocol used. | |
User Agent | ||
attributes.user_agent.original | Original user agent string, providing client software and OS. | |
Custom Attributes | ||
attributes.custom[“custom.attribute”] | Custom attribute provided in the trace. | |
attributes.custom[“dice.rollResult”] | Result of a dice roll operation. | |
attributes.custom[“operation.success”] | Indicates if the operation was successful. | |
attributes.custom[“player.name”] | Name of the player in the operation. | |
Operational Details | ||
duration | Time taken for the operation. | |
kind | Type of span (e.g., server, client, internal). | |
name | Name of the span. | |
Resource Attributes | ||
resource.custom.environment | Environment where the trace was captured, e.g., development. | |
Telemetry SDK Attributes | ||
telemetry.sdk.language | Language of the telemetry SDK, e.g., dotnet. | |
telemetry.sdk.name | Name of the telemetry SDK, e.g., opentelemetry. | |
telemetry.sdk.version | Version of the telemetry SDK, e.g., 1.7.0. | |
Service Attributes | ||
service.instance.id | Unique identifier for the instance of the service. | |
service.name | Name of the service generating the trace, e.g., dotnet. | |
service.version | Version of the service generating the trace, e.g., 1.0.0.0. | |
Scope Attributes | ||
scope.name | Name of the scope for the operation, e.g., OpenTelemetry.Instrumentation.AspNetCore. | |
scope.version | Version of the scope, e.g., 1.0.0.0. |
<PackageReference Include="OpenTelemetry" Version="1.7.0" />
This is the core SDK for OpenTelemetry in .NET. It provides the foundational tools needed to collect and manage telemetry data within your .NET applications. It’s the base upon which all other OpenTelemetry instrumentation and exporter packages build.
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.7.0" />
This package allows applications to export telemetry data to the console. It is primarily useful for development and testing purposes, offering a simple way to view the telemetry data your application generates in real time.
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0" />
This package enables your application to export telemetry data using the OpenTelemetry Protocol (OTLP) over gRPC or HTTP. It’s vital for sending data to observability platforms that support OTLP, ensuring your telemetry data can be easily analyzed and monitored across different systems.
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0" />
Designed for .NET applications, this package integrates OpenTelemetry with the .NET Generic Host. It simplifies the process of configuring and managing the lifecycle of OpenTelemetry resources such as TracerProvider, making it easier to collect telemetry data in applications that use the hosting model.
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.7.1" />
This package is designed for instrumenting ASP.NET Core applications. It automatically collects telemetry data about incoming requests and responses. This is important for monitoring the performance and reliability of web applications and APIs built with ASP.NET Core.
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.6.0-rc.1" />
This package provides automatic instrumentation for HTTP clients in .NET applications. It captures telemetry data about outbound HTTP requests, including details such as request and response headers, duration, success status, and more. It’s key for understanding external dependencies and interactions in your application.