|
| 1 | +--- |
| 2 | +title: Sentry SDK |
| 3 | +description: Use the Sentry SDK to send errors to Error Tracking. |
| 4 | +further_reading: |
| 5 | +- link: "/error_tracking/manage_data_collection" |
| 6 | + tag: "Documentation" |
| 7 | + text: "Manage Data Collection" |
| 8 | +--- |
| 9 | +{{< callout url="#" btn_hidden="true" >}} |
| 10 | +Using the Sentry SDK with Error Tracking is in Preview. |
| 11 | +{{< /callout >}} |
| 12 | + |
| 13 | +<div class="alert alert-warning"> |
| 14 | +Using the Sentry SDK with Error Tracking helps you migrate to Datadog. However, to get the most out of Error Tracking, it is recommended to use the regular setup. See <a href="/error_tracking/frontend">Frontend Error Tracking</a> and <a href="/error_tracking/backend">Backend Error Tracking</a>. |
| 15 | +</div> |
| 16 | + |
| 17 | +## Overview |
| 18 | +You can use [Sentry SDKs][1] to send your events to Datadog. This offers you a way to start using Error Tracking on existing applications that are monitored using Sentry SDKs. |
| 19 | + |
| 20 | +Setting up the Sentry SDK with Datadog requires a minimal code change to point the SDK to a Datadog Data Source Name (DSN). |
| 21 | + |
| 22 | +[Events][6] are sent to Datadog as logs. Non-error events (messages) also show up as logs. Other item types (traces, attachments, sessions, ...) are not supported. |
| 23 | + |
| 24 | +## Setup |
| 25 | +### Prerequisites |
| 26 | +- Sentry SDK events are sent into Datadog as **logs**. You must have [Error Tracking for Logs][2] enabled for errors to show up in Error Tracking. |
| 27 | + |
| 28 | +### Service configuration |
| 29 | +To configure the Sentry SDK to send events into Datadog: |
| 30 | +- Configure a Datadog Data Source Name (DSN). Follow the [in-app instructions][3] to generate your unique DSN. |
| 31 | +- Set a `service` tag on all events. This is used to separate errors and is shown in the Datadog UI. |
| 32 | + |
| 33 | +{{< tabs >}} |
| 34 | + |
| 35 | +{{% tab "JavaScript" %}} |
| 36 | +{{< code-block lang="javascript" >}} |
| 37 | +Sentry.init({ |
| 38 | + dsn: 'https://<TOKEN>@sentry-intake.<DD_SITE>/1', |
| 39 | + initialScope: { |
| 40 | + tags: { |
| 41 | + service: 'my-app' |
| 42 | + } |
| 43 | + } |
| 44 | +}); |
| 45 | +{{< /code-block >}} |
| 46 | +{{% /tab %}} |
| 47 | + |
| 48 | +{{% tab "Python" %}} |
| 49 | +{{< code-block lang="python" >}} |
| 50 | +sentry_sdk.init( |
| 51 | + dsn="https://<TOKEN>@sentry-intake.<DD_SITE>/1", |
| 52 | +) |
| 53 | +sentry_sdk.set_tag("service", "my-app") |
| 54 | +{{< /code-block >}} |
| 55 | +{{% /tab %}} |
| 56 | + |
| 57 | +{{% tab "Java" %}} |
| 58 | +{{< code-block lang="java" >}} |
| 59 | +Sentry.init(options -> { |
| 60 | + options.setDsn("https://<TOKEN>@sentry-intake.<DD_SITE>/1"); |
| 61 | +}); |
| 62 | +Sentry.configureScope(scope -> { |
| 63 | + scope.setTag("service", "my-app"); |
| 64 | +}); |
| 65 | +{{< /code-block >}} |
| 66 | +{{% /tab %}} |
| 67 | + |
| 68 | +{{% tab "C#" %}} |
| 69 | +{{< code-block lang="csharp">}} |
| 70 | +SentrySdk.Init(options => |
| 71 | +{ |
| 72 | + options.Dsn = "https://<TOKEN>@sentry-intake.<DD_SITE>/1"; |
| 73 | + options.SetBeforeSend((sentryEvent, hint) => { |
| 74 | + sentryEvent.SetTag("service", "my-app"); |
| 75 | + return sentryEvent; |
| 76 | + }); |
| 77 | +}); |
| 78 | +{{< /code-block >}} |
| 79 | +{{% /tab %}} |
| 80 | + |
| 81 | +{{% tab "Go" %}} |
| 82 | +{{< code-block lang="go">}} |
| 83 | +sentry.Init(sentry.ClientOptions{ |
| 84 | + Dsn: "https://<TOKEN>@sentry-intake.<DD_SITE>/1", |
| 85 | +}) |
| 86 | +sentry.ConfigureScope(func(scope *sentry.Scope) { |
| 87 | + scope.SetTag("service", "my-app"); |
| 88 | +}) |
| 89 | +{{< /code-block >}} |
| 90 | +{{% /tab %}} |
| 91 | + |
| 92 | +{{% tab "Ruby" %}} |
| 93 | +{{< code-block lang="ruby">}} |
| 94 | +Sentry.init do |config| |
| 95 | + config.dsn = https://<TOKEN>@sentry-intake.<DD_SITE>/1' |
| 96 | +end |
| 97 | +Sentry.set_tags('service': 'my-app') |
| 98 | +{{< /code-block >}} |
| 99 | +{{% /tab %}} |
| 100 | + |
| 101 | +{{< /tabs >}} |
| 102 | + |
| 103 | +### Upload JavaScript source maps |
| 104 | + |
| 105 | +If your frontend JavaScript source code is minified, you can upload source maps to Datadog to deobfuscate stack traces in Error Tracking. |
| 106 | + |
| 107 | +See [Upload JavaScript Source Maps][4]. |
| 108 | + |
| 109 | +Set a `version` tag on your events to match them to the correct source maps: |
| 110 | + |
| 111 | +{{< code-block lang="javascript" >}} |
| 112 | +Sentry.setTag("version", "v35.2395005"); |
| 113 | +{{< /code-block >}} |
| 114 | + |
| 115 | +### Source code integration |
| 116 | + |
| 117 | +[Datadog Source Code Integration][5] allows you to connect your telemetry with your Git repositories. |
| 118 | + |
| 119 | +Source Code Integration works with Sentry SDKs by configuring telemetry tags: |
| 120 | + |
| 121 | +{{< tabs >}} |
| 122 | + |
| 123 | +{{% tab "JavaScript" %}} |
| 124 | +{{< code-block lang="javascript" >}} |
| 125 | +Sentry.setTag("git.commit.sha", "<commitSha>"); |
| 126 | +Sentry.setTag("git.repository_url", "<git-provider.example/me/my-repo>"); |
| 127 | +{{< /code-block >}} |
| 128 | +{{% /tab %}} |
| 129 | + |
| 130 | +{{% tab "Python" %}} |
| 131 | +{{< code-block lang="python" >}} |
| 132 | +sentry_sdk.set_tag("git.commit.sha", "<commitSha>") |
| 133 | +sentry_sdk.set_tag("git.repository_url", "<git-provider.example/me/my-repo>") |
| 134 | +{{< /code-block >}} |
| 135 | +{{% /tab %}} |
| 136 | + |
| 137 | +{{% tab "Java" %}} |
| 138 | +{{< code-block lang="java" >}} |
| 139 | +Sentry.configureScope(scope -> { |
| 140 | + scope.setTag("git.commit.sha", "<commitSha>"); |
| 141 | + scope.setTag("git.repository_url", "<git-provider.example/me/my-repo>"); |
| 142 | +}); |
| 143 | +{{< /code-block >}} |
| 144 | +{{% /tab %}} |
| 145 | + |
| 146 | +{{% tab "C#" %}} |
| 147 | +{{< code-block lang="csharp" >}} |
| 148 | +SentrySdk.ConfigureScope(scope => |
| 149 | +{ |
| 150 | + scope.SetTag("git.commit.sha", "<commitSha>"); |
| 151 | + scope.SetTag("git.repository_url", "<git-provider.example/me/my-repo>"); |
| 152 | +}); |
| 153 | +{{< /code-block >}} |
| 154 | +{{% /tab %}} |
| 155 | + |
| 156 | +{{% tab "Go" %}} |
| 157 | +{{< code-block lang="go" >}} |
| 158 | +sentry.ConfigureScope(func(scope *sentry.Scope) { |
| 159 | + scope.SetTag("git.commit.sha", "<commitSha>"); |
| 160 | + scope.SetTag("git.repository_url", "<git-provider.example/me/my-repo>"); |
| 161 | +}) |
| 162 | +{{< /code-block >}} |
| 163 | +{{% /tab %}} |
| 164 | + |
| 165 | +{{% tab "Ruby" %}} |
| 166 | +{{< code-block lang="ruby" >}} |
| 167 | +Sentry.set_tags('git.commit.sha', '<commitSha>') |
| 168 | +Sentry.set_tags('git.repository_url', '<git-provider.example/me/my-repo>') |
| 169 | +{{< /code-block >}} |
| 170 | +{{% /tab %}} |
| 171 | + |
| 172 | +{{< /tabs >}} |
| 173 | + |
| 174 | +## Supported SDKs |
| 175 | + |
| 176 | +The following Sentry SDKs are verified to work with Error Tracking: |
| 177 | + |
| 178 | +<!-- TODO: test all latest versions --> |
| 179 | + |
| 180 | +| Platform | Tested version | |
| 181 | +| ---------- | -------------- | |
| 182 | +| JavaScript | | |
| 183 | +| Python | | |
| 184 | +| Java | | |
| 185 | +| .NET | | |
| 186 | +| Go | | |
| 187 | +| Ruby | | |
| 188 | + |
| 189 | +## Migrate to Datadog SDKs or Agent |
| 190 | + |
| 191 | +## Send events to both Sentry and Datadog |
| 192 | + |
| 193 | +<!-- TODO: code snippets --> |
| 194 | +<!-- TODO: move to other page? --> |
| 195 | + |
| 196 | +## Further Reading |
| 197 | + |
| 198 | +{{< partial name="whats-next/whats-next.html" >}} |
| 199 | + |
| 200 | +[1]: /error_tracking/frontend |
| 201 | +[2]: /error_tracking/backend |
| 202 | +[1]: https://docs.sentry.io/ |
| 203 | +[2]: https://app.datadoghq.com/error-tracking/settings |
| 204 | +[3]: https://app.datadoghq.com/error-tracking/settings/setup/sentry |
| 205 | +[4]: /real_user_monitoring/guide/upload-javascript-source-maps |
| 206 | +[5]: /integrations/guide/source-code-integration/ |
| 207 | +[6]: https://develop.sentry.dev/sdk/data-model/envelope-items/#event |
0 commit comments