Commit 26db37e
Add default OTEL telemetry settings to
## Why make this change?
`dab init` generates config with no telemetry section, requiring users
to manually edit config or run `dab add-telemetry` to enable standard
OpenTelemetry workflows. This is friction for .NET/Aspire and
containerized scenarios where OTEL env vars are already set by the
orchestrator.
## What is this change?
Adds default OpenTelemetry config to `TryCreateRuntimeConfig()` using
`@env()` references for standard OTEL environment variables. The
generated config now includes:
```json
"telemetry": {
"open-telemetry": {
"enabled": true,
"endpoint": "@env('OTEL_EXPORTER_OTLP_ENDPOINT')",
"headers": "@env('OTEL_EXPORTER_OTLP_HEADERS')",
"service-name": "@env('OTEL_SERVICE_NAME')"
}
}
```
Additionally, runtime config loading and OTLP exporter setup are
hardened to gracefully handle missing OTEL env vars:
- **`src/Cli/ConfigGenerator.cs`** — Added `TelemetryOptions` with
`OpenTelemetryOptions` to the `RuntimeConfig` constructed during init.
- **`src/Config/FileSystemRuntimeConfigLoader.cs`** — Changed
`TryLoadKnownConfig` to use
`EnvironmentVariableReplacementFailureMode.Ignore` so missing `@env()`
env vars don't crash config loading — they remain as literal `@env(...)`
strings.
- **`src/Service/Startup.cs`** — Added `Uri.TryCreate` validation in the
OTLP exporter setup guard condition. If the endpoint is null, empty, or
an unresolved `@env(...)` placeholder (not a valid URI), OTLP exporter
setup is skipped entirely and a warning is logged. Updated warning
message to reference "endpoint URI" instead of "connection string".
- **`src/Service/Program.cs`** — Applied the same `Uri.TryCreate`
validation for the logger factory OTLP setup, replacing the previous
`!string.IsNullOrWhiteSpace` + `new Uri()` pattern.
- **31 Verify snapshot files** — Updated to reflect the new telemetry
section.
- **`src/Cli.Tests/EndToEndTests.cs`** — E2E tests that deserialize
init-generated config with `doReplaceEnvVar: true` now use
`EnvironmentVariableReplacementFailureMode.Ignore` matching production
behavior. `TestAddTelemetry` assertion updated since telemetry is no
longer null after init.
## How was this tested?
- [x] Integration Tests
- [x] Unit Tests
All 43 `InitTests` pass. `EndToEndTests.TestInitForCosmosDBNoSql`
passes. E2E tests for `TestInitializingRestAndGraphQLGlobalSettings`,
`TestEnablingMultipleCreateOperation`, and `TestAddTelemetry` updated to
accommodate new defaults.
## Sample Request(s)
```bash
dab init --database-type mssql --connection-string "Server=localhost;Database=mydb;"
```
Generated `dab-config.json` now includes the `telemetry.open-telemetry`
section with `@env()` references. If the OTEL env vars are set at
runtime (e.g., by Aspire or a container orchestrator), telemetry export
works automatically. If unset, the `@env()` values remain as literal
strings, the endpoint fails `Uri.TryCreate` validation, and OTLP setup
is gracefully skipped.
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>dab init should automatically include default OTEL
settings </issue_title>
> <issue_description>## Problem
> Currently, when running `dab init`, the generated `dab-config.json`
does NOT include default configuration for OpenTelemetry telemetry using
the standard OTEL_* environment variables (such as
OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_SERVICE_NAME, etc.). This makes DAB
out-of-the-box telemetry support useless compared to typical .NET
applications and Aspire scenarios.
>
> ## Proposal
> When `dab init` is run in the CLI, if the telemetry section is being
generated (or whenever the user chooses to include telemetry),
automatically add the following default values to `dab-config.json`:
>
> ```json
> "telemetry": {
> "open-telemetry": {
> "enabled": true,
> "endpoint": "@env('OTEL_EXPORTER_OTLP_ENDPOINT')",
> "headers": "@env('OTEL_EXPORTER_OTLP_HEADERS')",
> "exporter-protocol": "@env('OTEL_EXPORTER_OTLP_PROTOCOL')",
> "service-name": "@env('OTEL_SERVICE_NAME')"
> }
> }
> ```
>
> These defaults should follow the documented OTEL env variable mapping,
so users can use standard .NET/OTEL workflows with container
orchestrators and Aspire. If the env vars are not set at runtime, the
config values should remain as-is or fall back gracefully.
>
> ## Benefit
> - Aligns DAB telemetry configuration with the "expected" .NET/Aspire
experience
> - Simplifies Aspire integration and containerized telemetry export
> - Reduces user error/misconfiguration
> - DAB users don't need to hand-edit config to enable standard OTEL
telemetry flows
>
> ## Implementation Guidance
> - Extend CLI config template logic to include the above section when
telemetry is requested/enabled
> - Consider surfacing a CLI flag to toggle inclusion of OTEL env
mappings
> - Document the behavior in `dab init` help and in DAB docs
>
> ---
> This is a feature request for improved developer out-of-the-box
experience. See [OpenTelemetry config
docs](https://learn.microsoft.com/en-us/azure/data-api-builder/concept/monitor/open-telemetry?tabs=bash)
for reference.</issue_description>
>
> <agent_instructions>introduce as little code as possible.
</agent_instructions>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #3161
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Co-authored-by: Aniruddh25 <3513779+Aniruddh25@users.noreply.github.com>
Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>dab init config generation (#3162)1 parent 883f4a1 commit 26db37e
48 files changed
Lines changed: 362 additions & 15 deletions
File tree
- src
- Cli.Tests
- Snapshots
- Cli
- Config
- Service.Tests/Snapshots
- Service
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
179 | 187 | | |
180 | 188 | | |
181 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
119 | | - | |
| 120 | + | |
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
| |||
196 | 197 | | |
197 | 198 | | |
198 | 199 | | |
199 | | - | |
| 200 | + | |
200 | 201 | | |
201 | 202 | | |
202 | 203 | | |
| |||
273 | 274 | | |
274 | 275 | | |
275 | 276 | | |
276 | | - | |
| 277 | + | |
277 | 278 | | |
278 | 279 | | |
279 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
169 | | - | |
| 168 | + | |
170 | 169 | | |
171 | 170 | | |
172 | 171 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
51 | 59 | | |
52 | 60 | | |
53 | 61 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
56 | 64 | | |
57 | 65 | | |
58 | 66 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
| |||
0 commit comments