- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
다음의 경우 OpenTelemetry API를 사용해 애플리케이션을 수동으로 계측해야 합니다.
ddtrace
라이브러리의 기능을 확장하고 싶습니다.ddtrace
라이브러리는 이러한 목표를 달성하는 데 도움이 됩니다. 다음 섹션에서는 커스텀 계측을 위해 Datadog과 OpenTelemetry API를 함께 사용하는 방법을 다룹니다.
To configure OpenTelemetry to use the Datadog trace provider:
Add your desired manual OpenTelemetry instrumentation to your .NET code following the OpenTelemetry .NET Manual Instrumentation documentation. Note: Where those instructions indicate that your code should call the OpenTelemetry SDK, call the Datadog tracing library instead.
Install the Datadog .NET tracing library and enable the tracer for your .NET Framework service or your .NET Core (and .NET 5+) service. Beta: You can optionally do this with Single Step APM Instrumentation.
Set DD_TRACE_OTEL_ENABLED
environment variable to true
.
Run your application.
Datadog combines these OpenTelemetry spans with other Datadog APM spans into a single trace of your application. It also supports OpenTelemetry instrumentation libraries.
To manually create spans that start a new, independent trace:
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
// Start a new span
using (Activity? activity = Telemetry.ActivitySource.StartActivity("<RESOURCE NAME>"))
{
activity?.SetTag("operation.name", "custom-operation");
// Do something
}
To create custom spans within an existing trace context:
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using (Activity? parentScope = Telemetry.ActivitySource.StartActivity("<RESOURCE NAME>"))
{
parentScope?.SetTag("operation.name", "manual.sortorders");
using (Activity? childScope = Telemetry.ActivitySource.StartActivity("<RESOURCE NAME>"))
{
// Nest using statements around the code to trace
childScope?.SetTag("operation.name", "manual.sortorders.child");
SortOrders();
}
}
Add custom tags to your spans to provide additional context:
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
public class ShoppingCartController : Controller
{
private IShoppingCartRepository _shoppingCartRepository;
[HttpGet]
public IActionResult Index(int customerId)
{
Activity? activity =
Telemetry.ActivitySource.StartActivity("<RESOURCE NAME>")
// Add a tag to the span for use in the Datadog web UI
activity?.SetTag("customer.id", customerId.ToString());
var cart = _shoppingCartRepository.Get(customerId);
return View(cart);
}
}
Set error information on a span when an error occurs during its execution.
try
{
// do work that can throw an exception
}
catch(Exception e)
{
activity?.SetTag("error", 1);
activity?.SetTag("error.message", exception.Message);
activity?.SetTag("error.stack", exception.ToString());
activity?.SetTag("error.type", exception.GetType().ToString());
}
You can add span events using the AddEvent
API. This method requires an ActivityEvent
constructed with the name
parameter and optionally accepts attributes
and timestamp
parameters. The method creates a new span event with the specified properties and associates it with the corresponding span.
DateTimeOffset
object.The following examples demonstrate different ways to add events to a span:
var eventTags = new ActivityTagsCollection
{
{ "int_val", 1 },
{ "string_val", "two" },
{ "int_array", new int[] { 3, 4 } },
{ "string_array", new string[] { "5", "6" } },
{ "bool_array", new bool[] { true, false } }
};
activity.AddEvent(new ActivityEvent("Event With No Attributes"));
activity.AddEvent(new ActivityEvent("Event With Some Attributes", DateTimeOffset.Now, eventTags));
Read the OpenTelemetry specification for more information.
You can configure the propagation of context for distributed traces by injecting and extracting headers. Read Trace Context Propagation for information.