Skip to content

Commit 663ffab

Browse files
authored
feat(go): refactor options page (#15123)
1 parent 987774e commit 663ffab

File tree

2 files changed

+249
-118
lines changed
  • docs/platforms/go/common/configuration
  • platform-includes/configuration/config-intro

2 files changed

+249
-118
lines changed

docs/platforms/go/common/configuration/options.mdx

Lines changed: 242 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -6,125 +6,251 @@ description: "Learn more about how the SDK can be configured via options. These
66

77
<PlatformContent includePath="configuration/config-intro" />
88

9+
## Core Options
10+
11+
Options that can be read from an environment variable (`SENTRY_DSN`, `SENTRY_ENVIRONMENT`, `SENTRY_RELEASE`) are read automatically.
12+
13+
<SdkOption name="Dsn" type="string" envVar="SENTRY_DSN">
14+
15+
The DSN tells the SDK where to send the events. If this value is not provided, the SDK will try to read it from the `SENTRY_DSN` environment variable. If that's also missing, no events will be sent.
16+
17+
Learn more about [DSN utilization](/product/sentry-basics/dsn-explainer/#dsn-utilization).
18+
19+
</SdkOption>
20+
21+
<SdkOption name="Debug" type="bool" defaultValue="false">
22+
23+
If debug is enabled, the SDK will attempt to print out useful debugging information if something goes wrong while sending the event. It's always `false` by default and generally not recommended in production environments, though it's safe to use.
24+
25+
</SdkOption>
26+
27+
<SdkOption name="Release" type="string" envVar="SENTRY_RELEASE">
28+
29+
Sets the release. Some Sentry features are built around release info, so reporting releases can help improve the overall experience. See [the releases documentation](/product/releases/).
30+
31+
If Release is not set, the SDK will try to derive a default value from environment variables or the Git repository in the working directory.
32+
33+
If you distribute a compiled binary, it is recommended to set the Release value explicitly at build time. As an example, you can use:
34+
935
```go
10-
// ClientOptions that configures a SDK Client
11-
type ClientOptions struct {
12-
// The DSN to use. If the DSN is not set, the client is effectively
13-
// disabled.
14-
Dsn string
15-
// In debug mode, the debug information is printed to stdout to help you
16-
// understand what Sentry is doing.
17-
Debug bool
18-
// Configures whether SDK should generate and attach stack traces to pure
19-
// capture message calls.
20-
AttachStacktrace bool
21-
// The sample rate for event submission in the range [0.0, 1.0]. By default,
22-
// all events are sent. Thus, as a historical special case, the sample rate
23-
// 0.0 is treated as if it was 1.0. To drop all events, set the DSN to the
24-
// empty string.
25-
SampleRate float64
26-
// Enable structured logging.
27-
EnableLogs bool
28-
// Enable performance tracing.
29-
EnableTracing bool
30-
// The sample rate for sampling traces in the range [0.0, 1.0].
31-
TracesSampleRate float64
32-
// Used to customize the sampling of traces, overrides TracesSampleRate.
33-
TracesSampler TracesSampler
34-
// The sample rate for profiling traces in the range [0.0, 1.0].
35-
// This is relative to TracesSampleRate - it is a ratio of profiled traces out of all sampled traces.
36-
ProfilesSampleRate float64
37-
// List of regexp strings that will be used to match against event's message
38-
// and if applicable, caught errors type and value.
39-
// If the match is found, then a whole event will be dropped.
40-
IgnoreErrors []string
41-
// List of regexp strings that will be used to match against a transaction's
42-
// name. If a match is found, then the transaction will be dropped.
43-
IgnoreTransactions []string
44-
// If this flag is enabled, certain personally identifiable information (PII) is added by active integrations.
45-
// By default, no such data is sent.
46-
SendDefaultPII bool
47-
// BeforeSend is called before error events are sent to Sentry.
48-
// Use it to mutate the event or return nil to discard the event.
49-
BeforeSend func(event *Event, hint *EventHint) *Event
50-
// BeforeSendTransaction is called before transaction events are sent to Sentry.
51-
// Use it to mutate the transaction or return nil to discard the transaction.
52-
BeforeSendTransaction func(event *Event, hint *EventHint) *Event
53-
// Before breadcrumb add callback.
54-
BeforeBreadcrumb func(breadcrumb *Breadcrumb, hint *BreadcrumbHint) *Breadcrumb
55-
// Integrations to be installed on the current Client, receives default
56-
// integrations.
57-
Integrations func([]Integration) []Integration
58-
// io.Writer implementation that should be used with the Debug mode.
59-
DebugWriter io.Writer
60-
// The transport to use. Defaults to HTTPTransport.
61-
Transport Transport
62-
// The server name to be reported.
63-
ServerName string
64-
// The release to be sent with events.
65-
//
66-
// Some Sentry features are built around releases, and, thus, reporting
67-
// events with a non-empty release improves the product experience. See
68-
// https://docs.sentry.io/product/releases/.
69-
//
70-
// If Release is not set, the SDK will try to derive a default value
71-
// from environment variables or the Git repository in the working
72-
// directory.
73-
//
74-
// If you distribute a compiled binary, it is recommended to set the
75-
// Release value explicitly at build time. As an example, you can use:
76-
//
77-
// go build -ldflags='-X main.release=VALUE'
78-
//
79-
// That will set the value of a predeclared variable 'release' in the
80-
// 'main' package to 'VALUE'. Then, use that variable when initializing
81-
// the SDK:
82-
//
83-
// sentry.Init(ClientOptions{Release: release})
84-
//
85-
// See https://golang.org/cmd/go/ and https://golang.org/cmd/link/ for
86-
// the official documentation of -ldflags and -X, respectively.
87-
Release string
88-
// The dist to be sent with events.
89-
Dist string
90-
// The environment to be sent with events.
91-
Environment string
92-
// Maximum number of breadcrumbs
93-
// when MaxBreadcrumbs is negative then ignore breadcrumbs.
94-
MaxBreadcrumbs int
95-
// Maximum number of spans.
96-
//
97-
// See https://develop.sentry.dev/sdk/data-model/envelopes/#size-limits for size limits
98-
// applied during event ingestion. Events that exceed these limits might get dropped.
99-
MaxSpans int
100-
// An optional pointer to http.Client that will be used with a default
101-
// HTTPTransport. Using your own client will make HTTPTransport, HTTPProxy,
102-
// HTTPSProxy and CaCerts options ignored.
103-
HTTPClient *http.Client
104-
// An optional pointer to http.Transport that will be used with a default
105-
// HTTPTransport. Using your own transport will make HTTPProxy, HTTPSProxy
106-
// and CaCerts options ignored.
107-
HTTPTransport http.RoundTripper
108-
// An optional HTTP proxy to use.
109-
// This will default to the HTTP_PROXY environment variable.
110-
HTTPProxy string
111-
// An optional HTTPS proxy to use.
112-
// This will default to the HTTPS_PROXY environment variable.
113-
// HTTPS_PROXY takes precedence over HTTP_PROXY for https requests.
114-
HTTPSProxy string
115-
// An optional set of SSL certificates to use.
116-
CaCerts *x509.CertPool
117-
// MaxErrorDepth is the maximum number of errors reported in a chain of errors.
118-
// This protects the SDK from an arbitrarily long chain of wrapped errors.
119-
//
120-
// An additional consideration is that arguably reporting a long chain of errors
121-
// is of little use when debugging production errors with Sentry. The Sentry UI
122-
// is not optimized for long chains either. The top-level error together with a
123-
// stack trace is often the most useful information.
124-
MaxErrorDepth int
125-
}
36+
go build -ldflags='-X main.release=VALUE'
12637
```
12738

39+
That will set the value of a predeclared variable 'release' in the 'main' package to 'VALUE'. Then, use that variable when initializing the SDK:
40+
41+
```go
42+
sentry.Init(ClientOptions{Release: release})
43+
```
44+
45+
See https://golang.org/cmd/go/ and https://golang.org/cmd/link/ for the official documentation of -ldflags and -X, respectively.
46+
47+
</SdkOption>
48+
49+
<SdkOption name="Dist" type="string">
50+
51+
Sets the distribution of the application. Distributions are used to disambiguate build or deployment variants of the same release of an application. For example, the dist can be the build number of an Xcode build or the version code of an Android build. The dist has a max length of 64 characters.
52+
53+
</SdkOption>
54+
55+
<SdkOption name="Environment" type="string" envVar="SENTRY_ENVIRONMENT">
56+
57+
Sets the environment. This string is freeform and not set by default. A release can be associated with more than one environment to separate them in the UI (think `staging` vs `prod` or similar).
58+
59+
By default, the SDK will try to read this value from the `SENTRY_ENVIRONMENT` environment variable.
60+
61+
Environments tell you where an error occurred, whether that's in your production system, your staging server, or elsewhere. Sentry automatically creates an environment when it receives an event with the environment parameter set.
62+
63+
</SdkOption>
64+
65+
<SdkOption name="SampleRate" type="float64" defaultValue="1.0">
66+
67+
Configures the sample rate for error events, in the range of `0.0` to `1.0`. The default is `1.0`, which means that 100% of error events will be sent. If set to `0.1`, only 10% of error events will be sent. Events are picked randomly.
68+
69+
As a historical special case, the sample rate `0.0` is treated as if it was `1.0`. To drop all events, set the DSN to an empty string.
70+
71+
</SdkOption>
72+
73+
<SdkOption name="MaxBreadcrumbs" type="int" defaultValue="100">
74+
75+
This variable controls the total amount of breadcrumbs that should be captured. However, you should be aware that Sentry has a [maximum payload size](https://develop.sentry.dev/sdk/data-model/envelopes/#size-limits) and any events exceeding that payload size will be dropped.
76+
77+
If MaxBreadcrumbs is given a negative value, breadcrumbs are ignored.
78+
79+
</SdkOption>
80+
81+
<SdkOption name="AttachStacktrace" type="bool" defaultValue="false">
82+
83+
When enabled, stack traces are automatically attached to all messages logged. Stack traces are always attached to errors; however, when this option is set, stack traces are also sent with messages. This option, for instance, means that stack traces appear next to all log messages.
84+
85+
This option is turned off by default.
86+
87+
Grouping in Sentry is different for events with stack traces and without. As a result, you will get new groups as you enable or disable this flag for certain events.
88+
89+
</SdkOption>
90+
91+
<SdkOption name="SendDefaultPII" type="bool" defaultValue="false">
92+
93+
If this flag is enabled, certain personally identifiable information (PII) is added by active integrations. By default, no such data is sent.
94+
95+
If you enable this option, be sure to manually remove what you don't want to send using our features for managing [_Sensitive Data_](../../data-management/sensitive-data/).
96+
97+
</SdkOption>
98+
99+
<SdkOption name="ServerName" type="string">
100+
101+
Supplies a server name. When provided, the name of the server is sent along and persisted in the event. For many integrations, the server name actually corresponds to the device hostname, even in situations where the machine is not actually a server.
102+
103+
104+
</SdkOption>
105+
106+
<SdkOption name="IgnoreErrors" type="[]string">
107+
108+
A list of regular expression strings used to match an event’s message, and, when applicable, the type or value of a caught error. If a match is found, the entire event is dropped.
109+
110+
By default, no errors are ignored.
111+
112+
</SdkOption>
113+
114+
115+
116+
<SdkOption name="MaxErrorDepth" type="int" defaultValue="100">
117+
118+
This is the maximum number of errors reported in a chain of errors. This protects the SDK from an arbitrarily long chain of wrapped errors.
119+
120+
In practice, reporting very long chains usually provides little value when debugging production issues, as the Sentry UI isn’t optimized for them. The top-level error and its stack trace usually contain the most relevant information.
121+
122+
</SdkOption>
123+
124+
## Logging Options
125+
126+
<SdkOption name="EnableLogs" type="bool" defaultValue="false">
127+
128+
Set this option to `true` to enable log capturing in Sentry. The SDK will only capture and send log messages to Sentry if this option is enabled.
129+
130+
</SdkOption>
131+
132+
## Tracing Options
133+
134+
<SdkOption name="EnableTracing" type="bool" defaultValue="false">
135+
136+
Enables performance tracing. When enabled, the SDK will create transactions and spans to measure performance.
137+
138+
</SdkOption>
139+
140+
<SdkOption name="TracesSampleRate" type="float64" defaultValue="0.0" envVar="SENTRY_TRACES_SAMPLE_RATE">
141+
142+
A number between `0.0` and `1.0`, controlling the percentage chance a given transaction will be sent to Sentry (`0.0` represents 0% while `1.0` represents 100%.) Applies equally to all transactions created in the app. Either this or `traces-sampler` must be defined to enable tracing.
143+
144+
</SdkOption>
145+
146+
<SdkOption name="TracesSampler" type="TracesSampler">
147+
148+
Used to customize the sampling of traces, overrides `TracesSampleRate`. This is a function responsible for determining the percentage chance a given transaction will be sent to Sentry. It will automatically be passed information about the transaction and the context in which it's being created, and must return a number between `0` (0% chance of being sent) and `1` (100% chance of being sent). Can also be used for filtering transactions, by returning 0 for those that are unwanted. Either this or `TracesSampleRate` must be defined to enable tracing.
149+
150+
</SdkOption>
151+
152+
<SdkOption name="MaxSpans" type="int" defaultValue="1000">
153+
154+
Maximum number of spans that can be attached to a transaction.
155+
156+
See https://develop.sentry.dev/sdk/data-model/envelopes/#size-limits for size limits applied during event ingestion. Events that exceed these limits might get dropped.
157+
158+
</SdkOption>
159+
160+
161+
<SdkOption name="IgnoreTransactions" type="[]string">
162+
163+
A list of regexp strings that will be used to match against a transaction's name. If a match is found, then the transaction will be dropped.
164+
165+
By default, no transactions are ignored.
166+
167+
</SdkOption>
168+
169+
## Hooks
170+
171+
These options can be used to hook the SDK in various ways to customize the reporting of events.
172+
173+
<SdkOption name="BeforeSend" type="func(event *Event, hint *EventHint) *Event">
174+
175+
This function is called with an event object, and can return a modified event object, or `nil` to skip reporting the event. This can be used, for instance, for manual PII stripping before sending.
176+
177+
By the time `BeforeSend` is executed, all scope data has already been applied to the event. Further modification of the scope won't have any effect.
178+
179+
</SdkOption>
180+
181+
<SdkOption name="BeforeSendTransaction" type="func(event *Event, hint *EventHint) *Event">
182+
183+
This function is called with a transaction object, and can return a modified transaction object, or `nil` to skip reporting the transaction. One way this might be used is for manual PII stripping before sending.
184+
185+
</SdkOption>
186+
187+
<SdkOption name="BeforeBreadcrumb" type="func(breadcrumb *Breadcrumb, hint *BreadcrumbHint) *Breadcrumb">
188+
189+
This function is called with a breadcrumb object before the breadcrumb is added to the scope. When `nil` is returned from the function, the breadcrumb is dropped. To pass the breadcrumb through, return the first argument, which contains the breadcrumb object.
190+
The callback typically gets a second argument (called a "hint") that provides the original object used to create the breadcrumb. You can use this to further customize the breadcrumb’s content or appearance.
191+
192+
</SdkOption>
193+
194+
## Integration Configuration
195+
196+
<SdkOption name="Integrations" type="func([]Integration) []Integration">
197+
198+
Integrations to be installed on the current Client, receives default integrations. This function can be used to add additional integrations or remove default integrations. For more information, please see our documentation for a specific integration.
199+
200+
See the [Removing Default Integrations](#removing-default-integrations) section below for an example.
201+
202+
</SdkOption>
203+
204+
<SdkOption name="DebugWriter" type="io.Writer">
205+
206+
`io.Writer` implementation that should be used with the Debug mode. This allows you to redirect debug output to a custom writer instead of stdout.
207+
208+
</SdkOption>
209+
210+
## Transport Options
211+
212+
Transports are used to send events to Sentry. Transports can be customized to some degree to better support highly specific deployments.
213+
214+
<SdkOption name="Transport" type="Transport">
215+
216+
The transport to use. Defaults to `HTTPTransport`. Switches out the transport used to send events. How this works depends on the SDK. It can, for instance, be used to capture events for unit-testing or to send it through some more complex setup that requires proxy authentication.
217+
218+
</SdkOption>
219+
220+
<SdkOption name="HTTPClient" type="*http.Client">
221+
222+
An optional pointer to `http.Client` that will be used with a default HTTPTransport. Using your own client will make HTTPTransport, HTTPProxy, HTTPSProxy and CaCerts options ignored.
223+
224+
</SdkOption>
225+
226+
<SdkOption name="HTTPTransport" type="http.RoundTripper">
227+
228+
An optional pointer to http.Transport that will be used with a default HTTPTransport. Using your own transport will make HTTPProxy, HTTPSProxy and CaCerts options ignored.
229+
230+
</SdkOption>
231+
232+
<SdkOption name="HTTPProxy" type="string" envVar="HTTP_PROXY">
233+
234+
When set, a proxy can be configured that should be used for outbound requests. This is also used for HTTPS requests unless a separate `HTTPSProxy` is configured.
235+
236+
This will default to the HTTP_PROXY environment variable.
237+
238+
</SdkOption>
239+
240+
<SdkOption name="HTTPSProxy" type="string" envVar="HTTPS_PROXY">
241+
242+
Configures a separate proxy for outgoing HTTPS requests. If this option is not provided but `HTTPProxy` is, then `HTTPProxy` is used for HTTPS requests too.
243+
244+
This will default to the HTTPS_PROXY environment variable. HTTPS_PROXY takes precedence over HTTP_PROXY for https requests.
245+
246+
</SdkOption>
247+
248+
<SdkOption name="CaCerts" type="*x509.CertPool">
249+
250+
An optional set of SSL certificates to use. See the [Providing SSL Certificates](#providing-ssl-certificates) section below for an example.
251+
252+
</SdkOption>
253+
128254
### Providing SSL Certificates
129255

130256
By default, TLS uses the host's root CA set. If you don't have `ca-certificates` (which should be your go-to way of fixing the issue of the missing certificates) and want to use `gocertifi` instead, you can provide pre-loaded cert files as one of the options to the `sentry.Init` call:

platform-includes/configuration/config-intro/go.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ Options are passed to the `Init()` method as an instance of `sentry.ClientOption
33

44
```go
55
sentry.Init(sentry.ClientOptions{
6-
Dsn: "___PUBLIC_DSN___",
7-
Debug: true,
6+
Dsn: "___PUBLIC_DSN___",
7+
// Enable printing of SDK debug messages.
8+
// Useful when getting started or trying to figure something out.
9+
Debug: true,
10+
// Adds request headers and IP for users,
11+
// visit: https://docs.sentry.io/platforms/go/data-management/data-collected/ for more info
12+
SendDefaultPII: true,
813
// Release: "[email protected]",
914
})
1015
```

0 commit comments

Comments
 (0)