Sending errors
Overview
The observability plugin automatically sends errors to LaunchDarkly. You can also use recordError to manually send a custom error.
Details about each SDK’s configuration are available in the SDK-specific sections below:
Viewing errors and sourcemaps
You can view all errors sent to LaunchDarkly under Errors in the LaunchDarkly user interface. To learn more, read Error monitoring.
If you are working with a client-side SDK and using the Errors page in LaunchDarkly to help debug an error, it’s helpful to have a stack trace from the original file in your codebase to help understand what is going wrong. To provide this, LaunchDarkly needs access to the sourcemaps from your codebase. You can send your sourcemaps to LaunchDarkly using the ldcli sourcemaps upload command in the LaunchDarkly CLI. To learn how, read Use ldcli for uploading sourcemaps.
Client-side SDKs
This feature is available in the observability plugin for the following client-side SDKs:
iOS
Expand iOS code sample
You can use recordError to manually send a custom error:
To learn more, read recordError.
Android
Expand Android code sample
You can use recordError to manually send a custom error:
The attributes argument is optional. To construct it, use Attributes from the @opentelemetry/api.
JavaScript
Expand JavaScript code sample
You can use recordError to manually send a custom error:
The message and payload arguments are optional. To learn more, read recordError.
React Native
Expand React Native code sample
You can use recordError to manually send a custom error:
The attributes and options arguments are optional. To construct them, use Attributes and OtelSpan from the @opentelemetry/api. To learn more, read recordError.
React Web
To send a custom error with the React Web SDK, follow the example for JavaScript.
Vue
To send a custom error with the React Web SDK, follow the example for JavaScript.
Server-side SDKs
This feature is available in the observability plugin for the following server-side SDKs:
.NET (server-side)
Expand .NET (server-side) code sample
Use RecordError to manually send a custom error.
Here’s how:
You can optionally pass an array of attributes, which may include any attributes. We recommend using attributes from the OpenTelemetry specification. To learn more, read RecordLog.
Go
Expand Go code sample
Use RecordError to manually record an error in the current span.
Here’s how:
This function takes a Go context.Context and the error. You can optionally pass an array of additional attributes from the OpenTelemetry specification. To learn more, read RecordError.
Node.js (server-side)
Expand Node.js (server-side) code sample
Use recordError to manually send a custom error.
Here’s how:
The recordError method automatically provides trace context propagation, so you can leave the secureSessionId and requestId undefined. Alternatively, you have the option to set their values, to assist with the context propagation. You can parse values for secureSessionId and requestId from the incoming request using LDObserve.parseHeaders().
The optional metadata can include any attributes from the OpenTelemetry specification. To learn more, read recordError.
Python
Expand Python code sample
Use record_exception to manually send a custom error.
Here’s how:
Passing the Exception records the exception contents and stack trace. You can optionally pass an array of additional Attributes, which may include any attributes from the OpenTelemetry specification. To learn more, read record_exception.