Skip to content

Commit 781973d

Browse files
committed
Add tracing
1 parent f5e1418 commit 781973d

File tree

11 files changed

+221
-0
lines changed

11 files changed

+221
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Set Up Tracing
3+
description: "Learn how to enable tracing in your app and discover valuable performance insights of your application."
4+
sidebar_order: 4000
5+
---
6+
7+
With [tracing](/product/performance/), Sentry tracks your software performance, measuring metrics like throughput and latency, and displaying the impact of errors across multiple systems. Sentry captures distributed traces consisting of transactions and spans, which measure individual services and individual operations within those services. Learn more about our model in [Distributed Tracing](/product/sentry-basics/tracing/distributed-tracing/).
8+
9+
<Note>
10+
11+
If you’re adopting Tracing in a high-throughput environment, we recommend testing prior to deployment to ensure that your service’s performance characteristics maintain expectations.
12+
13+
</Note>
14+
15+
## Configure
16+
17+
First, enable tracing and configure the sample rate for transactions. Set the sample rate for your transactions by either:
18+
19+
- Setting a uniform sample rate for all transactions using the <PlatformIdentifier name="traces-sample-rate" /> option in your SDK config to a number between `0` and `1`. (For example, to send 20% of transactions, set <PlatformIdentifier name="traces-sample-rate" /> to `0.2`.)
20+
- Controlling the sample rate based on the transaction itself and the context in which it's captured, by providing a function to the <PlatformIdentifier name="traces-sampler" /> config option.
21+
22+
The two options are meant to be mutually exclusive. If you set both, <PlatformIdentifier name="traces-sampler" /> will take precedence.
23+
24+
<Alert level="info">
25+
26+
The Unreal Engine SDK doesn't currently support sampling functions on Windows/Linux (<PlatformIdentifier name="traces-sampler" />).
27+
28+
</Alert>
29+
30+
<PlatformContent includePath="performance/configure-sample-rate" />
31+
32+
Learn more about tracing <PlatformLink to="/configuration/options/#tracing-options">options</PlatformLink>, how to use the <PlatformLink to="/configuration/sampling/#setting-a-sampling-function">TracesSampler</PlatformLink> function, or how to <PlatformLink to="/configuration/sampling/#sampling-transaction-events">sample transactions</PlatformLink>.
33+
34+
## Verify
35+
36+
Test out tracing by starting and finishing a transaction, which you _must_ do so transactions can be sent to Sentry. Learn how in our <PlatformLink to="/tracing/instrumentation/custom-instrumentation/">Custom Instrumentation</PlatformLink> content.
37+
38+
While you're testing, set <PlatformIdentifier name="traces-sample-rate" /> to `1.0`, as that ensures that every transaction will be sent to Sentry. Once testing is complete, you may want to set a lower <PlatformIdentifier name="traces-sample-rate" /> value, or switch to using <PlatformIdentifier name="traces-sampler" /> to selectively sample and filter your transactions, based on contextual data.
39+
40+
## Next Steps
41+
42+
<PageGrid />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Custom Instrumentation
3+
description: "Learn how to capture performance data on any action in your app."
4+
sidebar_order: 20
5+
---
6+
7+
<Note>
8+
9+
To capture transactions and spans customized to your organization's needs, you must first <PlatformLink to="/tracing/">set up tracing.</PlatformLink>
10+
11+
</Note>
12+
13+
<PlatformContent includePath="performance/enable-manual-instrumentation" />
14+
15+
<PlatformContent includePath="performance/add-spans-example" />
16+
17+
## Distributed Tracing
18+
19+
In order to use distributed tracing with the Native SDK, follow the <PlatformLink to="/tracing/trace-propagation/custom-instrumentation/">custom instrumentation</PlatformLink> steps.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Instrumentation
3+
description: "Learn how to instrument tracing in your app."
4+
sidebar_order: 20
5+
---
6+
7+
<PageGrid />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Custom Instrumentation
3+
sidebar_order: 40
4+
---
5+
6+
<PlatformContent includePath="distributed-tracing/custom-instrumentation/" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Dealing with CORS Issues
3+
sidebar_order: 80
4+
---
5+
6+
If your frontend and backend are hosted on different domains (for example, your frontend is on `https://example.com` and your backend is on `https://api.example.com`), and the frontend does XHR/fetch requests to your backend, you'll need to configure your backend [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers) headers to ensure requests aren't blocked.
7+
8+
Configure your backend CORS to allow the `sentry-trace` and `baggage` headers.
9+
10+
Your server's response header configuration might look like: `"Access-Control-Allow-Headers: sentry-trace, baggage"`. Your configuration will be specific to your setup.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Trace Propagation
3+
description: "Learn how to connect events across applications/services."
4+
sidebar_order: 3000
5+
---
6+
7+
If the overall application landscape that you want to observe with Sentry consists of more than just a single service or application, distributed tracing can add a lot of value.
8+
9+
## What is Distributed Tracing?
10+
11+
In the context of tracing events across a distributed system, distributed tracing acts as a powerful debugging tool. Imagine your application as a vast network of interconnected parts. For example, your system might be spread across different servers or your application might split into different backend and frontend services, each potentially having their own technology stack.
12+
13+
When an error or performance issue occurs, it can be challenging to pinpoint the root cause due to the complexity of such a system. Distributed tracing helps you follow the path of an event as it travels through this intricate web, recording every step it takes. By examining these traces, you can reconstruct the sequence of events leading up to the event of interest, identify the specific components involved, and understand their interactions. This detailed visibility enables you to diagnose and resolve issues more effectively, ultimately improving the reliability and performance of your distributed system.
14+
15+
## Basic Example
16+
17+
Here's an example showing a distributed trace in Sentry:
18+
19+
<Include name="common-imgs/distributed-trace-in-sentry" />
20+
21+
This distributed trace shows a Vue app's `pageload` making a request to a Python backend, which then calls the `/api` endpoint of a Ruby microservice.
22+
23+
What happens in the background is that Sentry uses reads and further propagates two HTTP headers between your applications:
24+
25+
- `sentry-trace`
26+
- `baggage`
27+
28+
If you run any JavaScript applications in your distributed system, make sure that those two headers are added to your CORS allowlist and won't be blocked or stripped by your proxy servers, gateways, or firewalls.
29+
30+
## How to Use Distributed Tracing?
31+
32+
<PlatformContent includePath="distributed-tracing/how-to-use/" />
33+
34+
Remember that in order to propagate trace information through your whole distributed system, you have to use Sentry in all of the involved services and applications. Take a look at the respective SDK documentation to learn how distributed tracing can be enabled for each platform.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
On this page you will learn how to manually propagate trace information into and out of your Unreal Engine game.
2+
3+
Continuing a trace from an upstream service requires using `ContinueTrace()` that will create a transaction context with the provided `sentry-trace` header. The transaction started with the transaction context will contain everything needed to continue the trace.
4+
5+
```cpp
6+
// Get incoming tracing information
7+
const FString inTrace = ...
8+
TArray<FString>() inBaggage = ...
9+
10+
USentryTransactionContext* transactionContext =
11+
SentrySubsystem->ContinueTrace(inTrace, inBaggage);
12+
13+
USentryTransaction* transaction =
14+
SentrySubsystem->StartTransactionWithContext(transactionContext);
15+
```
16+
17+
To obtain trace header from a transaction or span, use `GetTrace()`. Pass the returned value to the downstream service. If communication happens over HTTP, we recommend you attach this header to the outgoing HTTP request.
18+
19+
The format of the `sentry-trace` header should follow the one defined in [the telemetry docs](https://develop.sentry.dev/sdk/telemetry/traces/#header-sentry-trace). It should consist of a 32 character hexadecimal string for the `traceId`, followed by a 16 character hexadecimal string for the `spanId` and an optional single character for the `sampled` flag. If the given string doesn't match this format, the update is ignored and the values in the transaction context will remain unchanged.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In order to use distributed tracing with the Native SDK, follow the <PlatformLink to="/tracing/trace-propagation/custom-instrumentation/">custom instrumentation</PlatformLink> steps.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
For example, if you want to create a transaction for a user interaction in your application:
2+
3+
```cpp
4+
// Let's say this method is called in a background thread when a user clicks on the checkout button.
5+
void perform_checkout() {
6+
USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>();
7+
8+
// This will create a new Transaction for you
9+
USentryTransactionContext* transactionContext = NewObject<USentryTransactionContext>();
10+
transactionContext->Initialize(
11+
TEXT("checkout"),
12+
TEXT("perform-checkout")
13+
);
14+
15+
USentryTransaction* transaction =
16+
SentrySubsystem->StartTransactionWithContext(transactionContext);
17+
18+
// Validate the cart
19+
USentrySpan* validationSpan = transaction->StartChild(
20+
TEXT("validation"),
21+
TEXT("validating shopping cart")
22+
);
23+
24+
validate_shopping_cart(); // Some long process, maybe a sync http request.
25+
26+
validationSpan->Finish();
27+
28+
// Process the order
29+
SentrySpan* processSpan = transaction->StartChild(
30+
TEXT("process"),
31+
TEXT("processing shopping cart")
32+
);
33+
34+
process_shopping_cart(); // Another time consuming process.
35+
36+
processSpan->Finish();
37+
38+
transaction->Finish();
39+
}
40+
```
41+
42+
This example will send a transaction named `checkout` to Sentry. The transaction will contain a `validation` span that measures how long `validate_shopping_cart()` took and a `process` span that measures `process_shopping_cart()`. Finally, the `transaction->Finish()` call will finish the transaction and send it to Sentry.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
```cpp {diff}
2+
#include "SentrySettings.h"
3+
4+
FConfigureSettingsDelegate SettingsDelegate;
5+
SettingsDelegate.BindDynamic(this, &USomeClass::ConfigureSettingsDelegate);
6+
7+
void USomeClass::ConfigureSettingsDelegate(USentrySettings* Settings)
8+
{
9+
Settings->TracesSampleRate = 0.2f;
10+
}
11+
12+
...
13+
14+
USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>();
15+
16+
SentrySubsystem->InitializeWithSettings(SettingsDelegate);
17+
```

0 commit comments

Comments
 (0)