diff --git a/src/platform-includes/distributed-tracing/custom-instrumentation/python.mdx b/src/platform-includes/distributed-tracing/custom-instrumentation/python.mdx index 6de131667761b1..24a08e41c12e4d 100644 --- a/src/platform-includes/distributed-tracing/custom-instrumentation/python.mdx +++ b/src/platform-includes/distributed-tracing/custom-instrumentation/python.mdx @@ -1,6 +1,6 @@ -Distributed tracing works out of the box for [supported frameworks](/platforms/python/usage/distributed-tracing/#how-to-use-distributed-tracing) and when performance monitoring is enabled. If you're using an unsupported framework or don't want to turn on performance monitoring, then you can set up custom instrumentation for distributed tracing. +Distributed tracing works out of the box for [supported frameworks](/platforms/python/usage/distributed-tracing/#how-to-use-distributed-tracing) and when performance monitoring is enabled. If you're using an unsupported framework or don't want to turn on performance monitoring, you can set up custom instrumentation for distributed tracing. -This page descirbes how to manually propoage trace information into and out of your Python application. All you have to do is to make sure your application extracts incoming headers and to set those headers again when making an outgoing request within your application. +This page describes how to manually propagate trace information into and out of your Python application. All you have to do is to make sure your application extracts incoming headers and to set those headers again when making an outgoing request within your application. ## 1. Extract Incoming Tracing Information diff --git a/src/platform-includes/distributed-tracing/custom-instrumentation/ruby.mdx b/src/platform-includes/distributed-tracing/custom-instrumentation/ruby.mdx new file mode 100644 index 00000000000000..c7c7e6c4ae9477 --- /dev/null +++ b/src/platform-includes/distributed-tracing/custom-instrumentation/ruby.mdx @@ -0,0 +1,86 @@ +Distributed tracing works out of the box for supported frameworks and when performance monitoring is enabled. If you're using an unsupported framework or don't want to turn on performance monitoring, you can set up custom instrumentation for distributed tracing. + +This page describes how to manually propagate trace information into and out of your Ruby application. All you have to do is to make sure your application extracts incoming headers and to set those headers again when making an outgoing request within your application. + +## 1. Extract Incoming Tracing Information + +Incoming tracing information has to be extracted and stored in memory for later use. Sentry provides the `continue_trace` function to help you with this. Incoming tracing information can come from different places: + +- In a web environment, it's sent with HTTP headers, for example, by another Sentry SDK used in your frontend project. +- In a job queue, like Sidekiq / DelayedJob, it can be retrieved from meta or header variables. +- You also can pick up tracing information from environment variables. + +Here's an example of how to extract and store incoming tracing information using `continue_trace` in a Rack application where `env` is a typical hash of incoming HTTP headers: + +```ruby +# rack application +def call(env) + transaction = Sentry.continue_trace(env, name: 'transaction', op: 'op') + Sentry.start_transaction(transaction: transaction) +end +``` + +Sentry's `continue_trace` function will extract the given headers, try to find the `sentry-trace` and `baggage` headers, and store them in memory for later use. + +## 2. Inject Tracing Information to Outgoing Requests + +For distributed tracing to work, the two headers `sentry-trace` and `baggage`, must be added to outgoing requests. If you pregenerate HTML on the server-side, you might want to take a look at [Inject Tracing Information into Rendered HTML](#inject-tracing-information-into-rendered-html), which describes how to pass on tracing information through HTML meta tags. + +### Inject Tracing Information Into HTTP Requests + +The Ruby SDK intercepts all requests using `net/http` and adds this tracing information automatically to outgoing requests. + +If the gem you're using for making requests doesn't use `net/http` internally, you can generate this tracing information with the Sentry SDK's `get_traceparent`, `get_baggage` and `get_trace_propagation_headers` functions. Here's an example: + +```ruby +# using custom HTTPRequest implementation +HTTPRequest.get('https://example.com', headers: Sentry.get_trace_propagation_headers) +``` + +In this example, tracing information is propagated to the project running at `https://example.com`. If this project also uses a supported Sentry SDK, it will extract and save the tracing information for later use. + +The two services are now connected with your custom distributed tracing implementation. + +### Inject Tracing Information Into Rendered HTML + +To propagate tracing information into JavaScript running in rendered HTML, you have to inject HTML `meta` tags in your rendered HTML. For example, in a rails layout, you can inject the meta tags as follows: + +```erb {filename: app/views/layouts/application.html.erb} + + + + + > + > + + +

This is a website.

+ + +``` + +The rendered template will then look something like this: + +```html + + + + + + + + +

This is a website.

+ + +``` + +## Verification + +If you make outgoing requests from your project to other services, check if the headers `sentry-trace` and `baggage` are present in the request. If so, distributed tracing should work. diff --git a/src/platform-includes/distributed-tracing/how-to-use/ruby.mdx b/src/platform-includes/distributed-tracing/how-to-use/ruby.mdx new file mode 100644 index 00000000000000..cc3a221f934514 --- /dev/null +++ b/src/platform-includes/distributed-tracing/how-to-use/ruby.mdx @@ -0,0 +1,3 @@ +If you use the current version of our Ruby SDK, distributed tracing just works out of the box. No additional configuration is required. + +If you however use version `5.10.0` or below, you need to have our performance monitoring feature enabled for distributed tracing to work. diff --git a/src/platform-includes/distributed-tracing/limiting-traces/ruby.mdx b/src/platform-includes/distributed-tracing/limiting-traces/ruby.mdx new file mode 100644 index 00000000000000..50955cbe628db4 --- /dev/null +++ b/src/platform-includes/distributed-tracing/limiting-traces/ruby.mdx @@ -0,0 +1,12 @@ + + +```ruby +Sentry.init do |config| + config.dsn = '___PUBLIC_DSN___' + + # takes strings and regexes + config.trace_propagation_targets = ['myproject.org', /.*\.otherservice.org\/.*/] + + # ... +end +``` diff --git a/src/platforms/common/usage/distributed-tracing/custom-instrumentation.mdx b/src/platforms/common/usage/distributed-tracing/custom-instrumentation.mdx index 2ce82e91539698..c01561078a376d 100644 --- a/src/platforms/common/usage/distributed-tracing/custom-instrumentation.mdx +++ b/src/platforms/common/usage/distributed-tracing/custom-instrumentation.mdx @@ -7,6 +7,7 @@ supported: - php - java - android + - ruby --- diff --git a/src/platforms/common/usage/distributed-tracing/limiting-trace-propagation.mdx b/src/platforms/common/usage/distributed-tracing/limiting-trace-propagation.mdx index 69cdfe6acebf7e..4cd3148d1e9843 100644 --- a/src/platforms/common/usage/distributed-tracing/limiting-trace-propagation.mdx +++ b/src/platforms/common/usage/distributed-tracing/limiting-trace-propagation.mdx @@ -4,12 +4,13 @@ sidebar_order: 100 description: "" supported: - python + - ruby --- By default, trace information (`sentry-trace` and `baggage` headers) will be added to all outgoing HTTP requests. If you want to limit the URLs where trace information is added, you can specify that using the `trace_propagation_targets` option: -In the example above, trace information will be added to all requests to URLs that contain `"https://myproject.org"` and to all sub domains of `otherservice.org`, like `https://api.otherservice.org/something/` and `https://payment.otherservice.org/something/`. +In the example above, trace information will be added to all requests to URLs that contain `myproject.org` and to all sub domains of `otherservice.org`, like `https://api.otherservice.org/something/` and `https://payment.otherservice.org/something/`. See our config options documentation for more information about the `trace_propagation_targets` option.