Skip to content

Commit a0f5cf8

Browse files
authored
docs: [SDK-2206] add README for .NET AspSampleApp (#473)
## Summary Document how to run the sample ASP.NET Core app that exercises the LaunchDarkly.Observability plugin, including required env vars, endpoints, and flag names. Also rename the placeholder service name from "ryan-test-service" to "asp-core-test-service" in the sample and in the XML doc example on ObservabilityPlugin. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Documentation-only plus a sample configuration string change; no production/runtime logic is modified. > > **Overview** > Adds a new `AspSampleApp/README.md` documenting prerequisites, how to run the sample (including `LAUNCHDARKLY_SDK_KEY`), relevant flag names, and the available demo endpoints for exercising `Observe` APIs and flag evaluation. > > Renames the sample/placeholder `WithServiceName` value to `asp-core-test-service` in both `AspSampleApp/Program.cs` and the XML-doc example in `ObservabilityPlugin` to keep emitted telemetry labeling consistent. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 61932f2. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- ld-jira-link --> --- Related Jira issue: [SDK-2206: Improve ASP.Net Core example.](https://launchdarkly.atlassian.net/browse/SDK-2206) <!-- end-ld-jira-link -->
1 parent c677962 commit a0f5cf8

3 files changed

Lines changed: 79 additions & 2 deletions

File tree

sdk/@launchdarkly/observability-dotnet/AspSampleApp/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
var config = Configuration.Builder(Environment.GetEnvironmentVariable("LAUNCHDARKLY_SDK_KEY"))
1313
.Plugins(new PluginConfigurationBuilder()
1414
.Add(ObservabilityPlugin.Builder(builder.Services)
15-
.WithServiceName("ryan-test-service")
15+
.WithServiceName("asp-core-test-service")
1616
.WithServiceVersion("0.0.0")
1717
.Build())).Build();
1818

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# AspSampleApp
2+
3+
A minimal ASP.NET Core (net8.0) app that demonstrates the
4+
`LaunchDarkly.Observability` plugin. It exercises the public `Observe` APIs —
5+
exception recording, metrics, logs, manual spans — alongside a LaunchDarkly
6+
feature flag evaluation, so you can verify telemetry flows end-to-end.
7+
8+
The project references the local plugin source
9+
(`../src/LaunchDarkly.Observability`) rather than the published NuGet package,
10+
making it useful for plugin development as well.
11+
12+
## Prerequisites
13+
14+
- .NET 8 SDK
15+
- A LaunchDarkly server-side SDK key
16+
17+
## Running
18+
19+
From the `AspSampleApp/` directory:
20+
21+
```shell
22+
export LAUNCHDARKLY_SDK_KEY="<your-server-sdk-key>"
23+
dotnet run
24+
```
25+
26+
The app listens on the ports configured by the ASP.NET Core launch profile
27+
(HTTPS redirect is enabled). In `Development`, Swagger UI is exposed at
28+
`/swagger`.
29+
30+
If you want the `/weatherforecast` and `/manualinstrumentation` endpoints to
31+
exhibit non-default behavior, create boolean flags named `isMercury` and
32+
`enableMetrics` in your LaunchDarkly project.
33+
34+
### Configuring the service
35+
36+
The plugin is configured in `Program.cs`:
37+
38+
```csharp
39+
var config = Configuration.Builder(Environment.GetEnvironmentVariable("LAUNCHDARKLY_SDK_KEY"))
40+
.Plugins(new PluginConfigurationBuilder()
41+
.Add(ObservabilityPlugin.Builder(builder.Services)
42+
.WithServiceName("asp-core-test-service")
43+
.WithServiceVersion("0.0.0")
44+
.Build())).Build();
45+
```
46+
47+
Change `WithServiceName` / `WithServiceVersion` to label the telemetry emitted
48+
by your run.
49+
50+
## Endpoints
51+
52+
| Method | Path | What it demonstrates |
53+
| ------ | ------------------------- | ---------------------------------------------------------------------------------------------------- |
54+
| GET | `/recordexception` | `Observe.RecordException` with custom attributes. |
55+
| GET | `/recordmetrics` | `RecordMetric` (gauge), `RecordCount`, `RecordIncr`, `RecordHistogram`, and `RecordUpDownCounter`. |
56+
| GET | `/recordlog` | `Observe.RecordLog` at varying severities with structured attributes. |
57+
| GET | `/manualinstrumentation` | `Observe.StartActivity` to create a manual span; gated by the `enableMetrics` flag. |
58+
| GET | `/weatherforecast` | Evaluates the `isMercury` flag and returns a forecast whose temperature range depends on the value. |
59+
| GET | `/crash` | Throws `NotImplementedException` to test unhandled-exception capture. |
60+
61+
Example:
62+
63+
```shell
64+
curl http://localhost:5247/recordmetrics
65+
curl http://localhost:5247/weatherforecast
66+
```
67+
68+
A ready-to-run request is also in `AspSampleApp.http` for JetBrains / VS Code
69+
HTTP clients.
70+
71+
## Verifying telemetry
72+
73+
Once the endpoints have been hit, traces, metrics, logs, and errors should
74+
appear in the LaunchDarkly observability UI under the service name configured
75+
above. The default backend is
76+
`https://pub.observability.app.launchdarkly.com`; override it on the plugin
77+
builder if you're pointing at a different environment.

sdk/@launchdarkly/observability-dotnet/src/LaunchDarkly.Observability/Asp/Core/ObservabilityPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class ObservabilityPlugin : Plugin
4242
/// var config = Configuration.Builder("your-sdk-key")
4343
/// .Plugins(new PluginConfigurationBuilder()
4444
/// .Add(ObservabilityPlugin.Builder(builder.Services)
45-
/// .WithServiceName("ryan-test-service")
45+
/// .WithServiceName("asp-core-test-service")
4646
/// .WithServiceVersion("example-sha")
4747
/// .Build())).Build();
4848
/// // Building the LdClient with the Observability plugin. This line will add services to the web application.

0 commit comments

Comments
 (0)