diff --git a/src/Cli.Tests/ConfigGeneratorTests.cs b/src/Cli.Tests/ConfigGeneratorTests.cs index 9621a8ce98..a3533381dd 100644 --- a/src/Cli.Tests/ConfigGeneratorTests.cs +++ b/src/Cli.Tests/ConfigGeneratorTests.cs @@ -176,6 +176,14 @@ public void TestSpecialCharactersInConnectionString() ""provider"": ""AppService"" }, ""mode"": ""production"" + }, + ""telemetry"": { + ""open-telemetry"": { + ""enabled"": true, + ""endpoint"": ""@env('OTEL_EXPORTER_OTLP_ENDPOINT')"", + ""headers"": ""@env('OTEL_EXPORTER_OTLP_HEADERS')"", + ""service-name"": ""@env('OTEL_SERVICE_NAME')"" + } } }, ""autoentities"": {}, diff --git a/src/Cli.Tests/EndToEndTests.cs b/src/Cli.Tests/EndToEndTests.cs index 99a9b77b6e..e3e32d5076 100644 --- a/src/Cli.Tests/EndToEndTests.cs +++ b/src/Cli.Tests/EndToEndTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using Azure.DataApiBuilder.Config.Converters; using Azure.DataApiBuilder.Product; using Cli.Constants; using Microsoft.Data.SqlClient; @@ -116,7 +117,7 @@ public void TestInitializingRestAndGraphQLGlobalSettings() string[] args = { "init", "-c", TEST_RUNTIME_CONFIG_FILE, "--connection-string", SAMPLE_TEST_CONN_STRING, "--database-type", "mssql", "--rest.path", "/rest-api", "--rest.enabled", "false", "--graphql.path", "/graphql-api" }; Program.Execute(args, _cliLogger!, _fileSystem!, _runtimeConfigLoader!); - DeserializationVariableReplacementSettings replacementSettings = new(azureKeyVaultOptions: null, doReplaceEnvVar: true, doReplaceAkvVar: true); + DeserializationVariableReplacementSettings replacementSettings = new(azureKeyVaultOptions: null, doReplaceEnvVar: true, doReplaceAkvVar: true, envFailureMode: EnvironmentVariableReplacementFailureMode.Ignore); Assert.IsTrue(_runtimeConfigLoader!.TryLoadConfig( TEST_RUNTIME_CONFIG_FILE, out RuntimeConfig? runtimeConfig, @@ -196,7 +197,7 @@ public void TestEnablingMultipleCreateOperation(CliBool isMultipleCreateEnabled, Program.Execute(args.ToArray(), _cliLogger!, _fileSystem!, _runtimeConfigLoader!); - DeserializationVariableReplacementSettings replacementSettings = new(azureKeyVaultOptions: null, doReplaceEnvVar: true, doReplaceAkvVar: true); + DeserializationVariableReplacementSettings replacementSettings = new(azureKeyVaultOptions: null, doReplaceEnvVar: true, doReplaceAkvVar: true, envFailureMode: EnvironmentVariableReplacementFailureMode.Ignore); Assert.IsTrue(_runtimeConfigLoader!.TryLoadConfig( TEST_RUNTIME_CONFIG_FILE, out RuntimeConfig? runtimeConfig, @@ -273,7 +274,7 @@ public void TestAddTelemetry(string? appInsightsEnabled, string appInsightsConnS // Perform assertions on various properties. Assert.IsNotNull(runtimeConfig); Assert.IsNotNull(runtimeConfig.Runtime); - Assert.IsNull(runtimeConfig.Runtime.Telemetry); + Assert.IsNotNull(runtimeConfig.Runtime.Telemetry); string[] addTelemetryArgs; if (appInsightsEnabled is null) diff --git a/src/Cli.Tests/EnvironmentTests.cs b/src/Cli.Tests/EnvironmentTests.cs index 2d6378cf74..d7b359783a 100644 --- a/src/Cli.Tests/EnvironmentTests.cs +++ b/src/Cli.Tests/EnvironmentTests.cs @@ -165,8 +165,7 @@ public async Task FailureToStartEngineWhenEnvVarNamedWrong() string? output = await process.StandardError.ReadLineAsync(); Assert.AreEqual("Deserialization of the configuration file failed during a post-processing step.", output); output = await process.StandardError.ReadToEndAsync(); - StringAssert.Contains(output, "Environmental Variable, " - + expectedEnvVarName + ", not found.", StringComparison.Ordinal); + StringAssert.Contains(output, "A valid Connection String should be provided.", StringComparison.Ordinal); process.Kill(); } diff --git a/src/Cli.Tests/Snapshots/EndToEndTests.TestAddingStoredProcedureWithRestMethodsAndGraphQLOperations.verified.txt b/src/Cli.Tests/Snapshots/EndToEndTests.TestAddingStoredProcedureWithRestMethodsAndGraphQLOperations.verified.txt index 11bf762b42..6fcd0d79b1 100644 --- a/src/Cli.Tests/Snapshots/EndToEndTests.TestAddingStoredProcedureWithRestMethodsAndGraphQLOperations.verified.txt +++ b/src/Cli.Tests/Snapshots/EndToEndTests.TestAddingStoredProcedureWithRestMethodsAndGraphQLOperations.verified.txt @@ -47,6 +47,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [ diff --git a/src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithSourceAsStoredProcedure.verified.txt b/src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithSourceAsStoredProcedure.verified.txt index 475149674b..67fb0f00dc 100644 --- a/src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithSourceAsStoredProcedure.verified.txt +++ b/src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithSourceAsStoredProcedure.verified.txt @@ -47,6 +47,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [ diff --git a/src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithSourceWithDefaultType.verified.txt b/src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithSourceWithDefaultType.verified.txt index 19c590a7f7..197f5588ed 100644 --- a/src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithSourceWithDefaultType.verified.txt +++ b/src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithSourceWithDefaultType.verified.txt @@ -47,6 +47,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [ diff --git a/src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithoutIEnumerables.verified.txt b/src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithoutIEnumerables.verified.txt index 2b4583dc36..36294a4882 100644 --- a/src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithoutIEnumerables.verified.txt +++ b/src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithoutIEnumerables.verified.txt @@ -48,6 +48,14 @@ Provider: AppService }, Mode: Production + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [ diff --git a/src/Cli.Tests/Snapshots/EndToEndTests.TestInitForCosmosDBNoSql.verified.txt b/src/Cli.Tests/Snapshots/EndToEndTests.TestInitForCosmosDBNoSql.verified.txt index 9be903b3bd..961c8022ef 100644 --- a/src/Cli.Tests/Snapshots/EndToEndTests.TestInitForCosmosDBNoSql.verified.txt +++ b/src/Cli.Tests/Snapshots/EndToEndTests.TestInitForCosmosDBNoSql.verified.txt @@ -53,6 +53,14 @@ Provider: AppService }, Mode: Production + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/EndToEndTests.TestUpdatingStoredProcedureWithRestMethods.verified.txt b/src/Cli.Tests/Snapshots/EndToEndTests.TestUpdatingStoredProcedureWithRestMethods.verified.txt index eae623f5a8..4a26b4f4fb 100644 --- a/src/Cli.Tests/Snapshots/EndToEndTests.TestUpdatingStoredProcedureWithRestMethods.verified.txt +++ b/src/Cli.Tests/Snapshots/EndToEndTests.TestUpdatingStoredProcedureWithRestMethods.verified.txt @@ -47,6 +47,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [ diff --git a/src/Cli.Tests/Snapshots/EndToEndTests.TestUpdatingStoredProcedureWithRestMethodsAndGraphQLOperations.verified.txt b/src/Cli.Tests/Snapshots/EndToEndTests.TestUpdatingStoredProcedureWithRestMethodsAndGraphQLOperations.verified.txt index 4be8d89e14..8f9e1e92f6 100644 --- a/src/Cli.Tests/Snapshots/EndToEndTests.TestUpdatingStoredProcedureWithRestMethodsAndGraphQLOperations.verified.txt +++ b/src/Cli.Tests/Snapshots/EndToEndTests.TestUpdatingStoredProcedureWithRestMethodsAndGraphQLOperations.verified.txt @@ -47,6 +47,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [ diff --git a/src/Cli.Tests/Snapshots/InitTests.CosmosDbNoSqlDatabase.verified.txt b/src/Cli.Tests/Snapshots/InitTests.CosmosDbNoSqlDatabase.verified.txt index 034276178e..cdb93dcb6f 100644 --- a/src/Cli.Tests/Snapshots/InitTests.CosmosDbNoSqlDatabase.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.CosmosDbNoSqlDatabase.verified.txt @@ -49,6 +49,14 @@ Provider: AppService }, Mode: Production + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.CosmosDbPostgreSqlDatabase.verified.txt b/src/Cli.Tests/Snapshots/InitTests.CosmosDbPostgreSqlDatabase.verified.txt index 64b71e6c59..d8429e91dc 100644 --- a/src/Cli.Tests/Snapshots/InitTests.CosmosDbPostgreSqlDatabase.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.CosmosDbPostgreSqlDatabase.verified.txt @@ -48,6 +48,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_171ea8114ff71814.verified.txt b/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_171ea8114ff71814.verified.txt index b89b9c70d1..397d6000a7 100644 --- a/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_171ea8114ff71814.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_171ea8114ff71814.verified.txt @@ -52,6 +52,14 @@ } }, Mode: Production + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_2df7a1794712f154.verified.txt b/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_2df7a1794712f154.verified.txt index ce2d025be4..af581f7a1f 100644 --- a/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_2df7a1794712f154.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_2df7a1794712f154.verified.txt @@ -48,6 +48,14 @@ Provider: Simulator }, Mode: Production + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_59fe1a10aa78899d.verified.txt b/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_59fe1a10aa78899d.verified.txt index 02e6387637..f87d986a88 100644 --- a/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_59fe1a10aa78899d.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_59fe1a10aa78899d.verified.txt @@ -48,6 +48,14 @@ Provider: StaticWebApps }, Mode: Production + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_b95b637ea87f16a7.verified.txt b/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_b95b637ea87f16a7.verified.txt index cca682e8c3..301f4ada85 100644 --- a/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_b95b637ea87f16a7.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_b95b637ea87f16a7.verified.txt @@ -48,6 +48,14 @@ Provider: AppService }, Mode: Production + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_daacbd948b7ef72f.verified.txt b/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_daacbd948b7ef72f.verified.txt index 657afc9ce6..59a34121a0 100644 --- a/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_daacbd948b7ef72f.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_daacbd948b7ef72f.verified.txt @@ -52,6 +52,14 @@ } }, Mode: Production + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.GraphQLPathWithoutStartingSlashWillHaveItAdded.verified.txt b/src/Cli.Tests/Snapshots/InitTests.GraphQLPathWithoutStartingSlashWillHaveItAdded.verified.txt index 86ba02fbcd..c85dc0d349 100644 --- a/src/Cli.Tests/Snapshots/InitTests.GraphQLPathWithoutStartingSlashWillHaveItAdded.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.GraphQLPathWithoutStartingSlashWillHaveItAdded.verified.txt @@ -48,6 +48,14 @@ Provider: AppService }, Mode: Production + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.MsSQLDatabase.verified.txt b/src/Cli.Tests/Snapshots/InitTests.MsSQLDatabase.verified.txt index 777642d9e0..7bee761b96 100644 --- a/src/Cli.Tests/Snapshots/InitTests.MsSQLDatabase.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.MsSQLDatabase.verified.txt @@ -51,6 +51,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.RestPathWithoutStartingSlashWillHaveItAdded.verified.txt b/src/Cli.Tests/Snapshots/InitTests.RestPathWithoutStartingSlashWillHaveItAdded.verified.txt index 5a19301e74..86b4a31499 100644 --- a/src/Cli.Tests/Snapshots/InitTests.RestPathWithoutStartingSlashWillHaveItAdded.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.RestPathWithoutStartingSlashWillHaveItAdded.verified.txt @@ -48,6 +48,14 @@ Provider: AppService }, Mode: Production + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.TestInitializingConfigWithoutConnectionString.verified.txt b/src/Cli.Tests/Snapshots/InitTests.TestInitializingConfigWithoutConnectionString.verified.txt index e40b268f89..d6a21f524c 100644 --- a/src/Cli.Tests/Snapshots/InitTests.TestInitializingConfigWithoutConnectionString.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.TestInitializingConfigWithoutConnectionString.verified.txt @@ -51,6 +51,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.TestSpecialCharactersInConnectionString.verified.txt b/src/Cli.Tests/Snapshots/InitTests.TestSpecialCharactersInConnectionString.verified.txt index cca682e8c3..301f4ada85 100644 --- a/src/Cli.Tests/Snapshots/InitTests.TestSpecialCharactersInConnectionString.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.TestSpecialCharactersInConnectionString.verified.txt @@ -48,6 +48,14 @@ Provider: AppService }, Mode: Production + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_0546bef37027a950.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_0546bef37027a950.verified.txt index e8193e5f14..7770641b1a 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_0546bef37027a950.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_0546bef37027a950.verified.txt @@ -51,6 +51,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_0ac567dd32a2e8f5.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_0ac567dd32a2e8f5.verified.txt index 777642d9e0..7bee761b96 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_0ac567dd32a2e8f5.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_0ac567dd32a2e8f5.verified.txt @@ -51,6 +51,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_0c06949221514e77.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_0c06949221514e77.verified.txt index d5b44393ec..0a7098ae32 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_0c06949221514e77.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_0c06949221514e77.verified.txt @@ -56,6 +56,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_18667ab7db033e9d.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_18667ab7db033e9d.verified.txt index 9a28bccd06..a93629a454 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_18667ab7db033e9d.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_18667ab7db033e9d.verified.txt @@ -48,6 +48,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_2f42f44c328eb020.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_2f42f44c328eb020.verified.txt index e8193e5f14..7770641b1a 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_2f42f44c328eb020.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_2f42f44c328eb020.verified.txt @@ -51,6 +51,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_3243d3f3441fdcc1.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_3243d3f3441fdcc1.verified.txt index 9a28bccd06..a93629a454 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_3243d3f3441fdcc1.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_3243d3f3441fdcc1.verified.txt @@ -48,6 +48,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_53350b8b47df2112.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_53350b8b47df2112.verified.txt index a8c2329c65..ac69456340 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_53350b8b47df2112.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_53350b8b47df2112.verified.txt @@ -48,6 +48,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_6584e0ec46b8a11d.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_6584e0ec46b8a11d.verified.txt index 5ed3cbcffd..3232f0d03e 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_6584e0ec46b8a11d.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_6584e0ec46b8a11d.verified.txt @@ -52,6 +52,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_81cc88db3d4eecfb.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_81cc88db3d4eecfb.verified.txt index 09377f9c51..d840a3121d 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_81cc88db3d4eecfb.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_81cc88db3d4eecfb.verified.txt @@ -56,6 +56,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_8ea187616dbb5577.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_8ea187616dbb5577.verified.txt index 51c90e1666..6d021464aa 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_8ea187616dbb5577.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_8ea187616dbb5577.verified.txt @@ -48,6 +48,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_905845c29560a3ef.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_905845c29560a3ef.verified.txt index e8193e5f14..7770641b1a 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_905845c29560a3ef.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_905845c29560a3ef.verified.txt @@ -51,6 +51,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_b2fd24fab5b80917.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_b2fd24fab5b80917.verified.txt index 5ed3cbcffd..3232f0d03e 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_b2fd24fab5b80917.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_b2fd24fab5b80917.verified.txt @@ -52,6 +52,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_bd7cd088755287c9.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_bd7cd088755287c9.verified.txt index 5ed3cbcffd..3232f0d03e 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_bd7cd088755287c9.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_bd7cd088755287c9.verified.txt @@ -52,6 +52,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_d2eccba2f836b380.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_d2eccba2f836b380.verified.txt index a8c2329c65..ac69456340 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_d2eccba2f836b380.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_d2eccba2f836b380.verified.txt @@ -48,6 +48,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_d463eed7fe5e4bbe.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_d463eed7fe5e4bbe.verified.txt index 51c90e1666..6d021464aa 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_d463eed7fe5e4bbe.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_d463eed7fe5e4bbe.verified.txt @@ -48,6 +48,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_d5520dd5c33f7b8d.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_d5520dd5c33f7b8d.verified.txt index a8c2329c65..ac69456340 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_d5520dd5c33f7b8d.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_d5520dd5c33f7b8d.verified.txt @@ -48,6 +48,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_eab4a6010e602b59.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_eab4a6010e602b59.verified.txt index 9a28bccd06..a93629a454 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_eab4a6010e602b59.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_eab4a6010e602b59.verified.txt @@ -48,6 +48,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_ecaa688829b4030e.verified.txt b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_ecaa688829b4030e.verified.txt index 51c90e1666..6d021464aa 100644 --- a/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_ecaa688829b4030e.verified.txt +++ b/src/Cli.Tests/Snapshots/InitTests.VerifyCorrectConfigGenerationWithMultipleMutationOptions_ecaa688829b4030e.verified.txt @@ -48,6 +48,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [] diff --git a/src/Cli/ConfigGenerator.cs b/src/Cli/ConfigGenerator.cs index d97971ecb5..62add15c31 100644 --- a/src/Cli/ConfigGenerator.cs +++ b/src/Cli/ConfigGenerator.cs @@ -280,7 +280,14 @@ public static bool TryCreateRuntimeConfig(InitOptions options, FileSystemRuntime Provider: options.AuthenticationProvider, Jwt: (options.Audience is null && options.Issuer is null) ? null : new(options.Audience, options.Issuer)), Mode: options.HostMode), - BaseRoute: runtimeBaseRoute + BaseRoute: runtimeBaseRoute, + Telemetry: new TelemetryOptions( + OpenTelemetry: new OpenTelemetryOptions( + Enabled: true, + Endpoint: "@env('OTEL_EXPORTER_OTLP_ENDPOINT')", + Headers: "@env('OTEL_EXPORTER_OTLP_HEADERS')", + ExporterProtocol: null, + ServiceName: "@env('OTEL_SERVICE_NAME')")) ), Entities: new RuntimeEntities(new Dictionary())); diff --git a/src/Config/FileSystemRuntimeConfigLoader.cs b/src/Config/FileSystemRuntimeConfigLoader.cs index 614cfbd11c..70b36d8294 100644 --- a/src/Config/FileSystemRuntimeConfigLoader.cs +++ b/src/Config/FileSystemRuntimeConfigLoader.cs @@ -6,6 +6,7 @@ using System.Net; using System.Reflection; using System.Text.Json; +using Azure.DataApiBuilder.Config.Converters; using Azure.DataApiBuilder.Config.ObjectModel; using Azure.DataApiBuilder.Config.Utilities; using Azure.DataApiBuilder.Service.Exceptions; @@ -304,7 +305,7 @@ public bool TryLoadConfig( public override bool TryLoadKnownConfig([NotNullWhen(true)] out RuntimeConfig? config, bool replaceEnvVar = false) { // Convert legacy replaceEnvVar parameter to replacement settings for backward compatibility - DeserializationVariableReplacementSettings? replacementSettings = new(azureKeyVaultOptions: null, doReplaceEnvVar: replaceEnvVar, doReplaceAkvVar: replaceEnvVar); + DeserializationVariableReplacementSettings? replacementSettings = new(azureKeyVaultOptions: null, doReplaceEnvVar: replaceEnvVar, doReplaceAkvVar: replaceEnvVar, envFailureMode: EnvironmentVariableReplacementFailureMode.Ignore); return TryLoadConfig(ConfigFilePath, out config, replacementSettings: replacementSettings); } diff --git a/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForCosmos.verified.txt b/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForCosmos.verified.txt index c9def099f9..c229da4ce6 100644 --- a/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForCosmos.verified.txt +++ b/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForCosmos.verified.txt @@ -51,6 +51,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [ diff --git a/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForMsSql.verified.txt b/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForMsSql.verified.txt index d80506e102..3459578f59 100644 --- a/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForMsSql.verified.txt +++ b/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForMsSql.verified.txt @@ -55,6 +55,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [ diff --git a/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForMySql.verified.txt b/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForMySql.verified.txt index e7f312ef48..d3393a7b89 100644 --- a/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForMySql.verified.txt +++ b/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForMySql.verified.txt @@ -47,6 +47,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [ diff --git a/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForPostgreSql.verified.txt b/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForPostgreSql.verified.txt index 5dcef0dcdb..f7d781fe64 100644 --- a/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForPostgreSql.verified.txt +++ b/src/Service.Tests/Snapshots/ConfigurationTests.TestReadingRuntimeConfigForPostgreSql.verified.txt @@ -47,6 +47,14 @@ Authentication: { Provider: AppService } + }, + Telemetry: { + OpenTelemetry: { + Enabled: true, + Endpoint: @env('OTEL_EXPORTER_OTLP_ENDPOINT'), + Headers: @env('OTEL_EXPORTER_OTLP_HEADERS'), + ServiceName: @env('OTEL_SERVICE_NAME') + } } }, Entities: [ diff --git a/src/Service/Program.cs b/src/Service/Program.cs index e23fb98cd9..c7e6cb10e5 100644 --- a/src/Service/Program.cs +++ b/src/Service/Program.cs @@ -220,7 +220,8 @@ public static ILoggerFactory GetLoggerFactoryForLogLevel( } } - if (Startup.OpenTelemetryOptions.Enabled && !string.IsNullOrWhiteSpace(Startup.OpenTelemetryOptions.Endpoint)) + if (Startup.OpenTelemetryOptions.Enabled + && Uri.TryCreate(Startup.OpenTelemetryOptions.Endpoint, UriKind.Absolute, out Uri? otlpEndpoint)) { builder.AddOpenTelemetry(logging => { @@ -229,7 +230,7 @@ public static ILoggerFactory GetLoggerFactoryForLogLevel( logging.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(Startup.OpenTelemetryOptions.ServiceName!)); logging.AddOtlpExporter(configure => { - configure.Endpoint = new Uri(Startup.OpenTelemetryOptions.Endpoint); + configure.Endpoint = otlpEndpoint; configure.Headers = Startup.OpenTelemetryOptions.Headers; configure.Protocol = OtlpExportProtocol.Grpc; }); diff --git a/src/Service/Startup.cs b/src/Service/Startup.cs index c24d8be8a8..f4caee4ed5 100644 --- a/src/Service/Startup.cs +++ b/src/Service/Startup.cs @@ -132,7 +132,8 @@ public void ConfigureServices(IServiceCollection services) if (runtimeConfigAvailable && runtimeConfig?.Runtime?.Telemetry?.OpenTelemetry is not null - && runtimeConfig.Runtime.Telemetry.OpenTelemetry.Enabled) + && runtimeConfig.Runtime.Telemetry.OpenTelemetry.Enabled + && Uri.TryCreate(runtimeConfig.Runtime.Telemetry.OpenTelemetry.Endpoint, UriKind.Absolute, out Uri? otlpEndpoint)) { services.Configure(options => { @@ -146,7 +147,7 @@ public void ConfigureServices(IServiceCollection services) logging.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(runtimeConfig.Runtime.Telemetry.OpenTelemetry.ServiceName!)) .AddOtlpExporter(configure => { - configure.Endpoint = new Uri(runtimeConfig.Runtime.Telemetry.OpenTelemetry.Endpoint!); + configure.Endpoint = otlpEndpoint; configure.Headers = runtimeConfig.Runtime.Telemetry.OpenTelemetry.Headers; configure.Protocol = OtlpExportProtocol.Grpc; }); @@ -160,7 +161,7 @@ public void ConfigureServices(IServiceCollection services) // .AddFusionCacheInstrumentation() .AddOtlpExporter(configure => { - configure.Endpoint = new Uri(runtimeConfig.Runtime.Telemetry.OpenTelemetry.Endpoint!); + configure.Endpoint = otlpEndpoint; configure.Headers = runtimeConfig.Runtime.Telemetry.OpenTelemetry.Headers; configure.Protocol = OtlpExportProtocol.Grpc; }) @@ -176,7 +177,7 @@ public void ConfigureServices(IServiceCollection services) .AddHotChocolateInstrumentation() .AddOtlpExporter(configure => { - configure.Endpoint = new Uri(runtimeConfig.Runtime.Telemetry.OpenTelemetry.Endpoint!); + configure.Endpoint = otlpEndpoint; configure.Headers = runtimeConfig.Runtime.Telemetry.OpenTelemetry.Headers; configure.Protocol = OtlpExportProtocol.Grpc; }) @@ -1049,9 +1050,10 @@ private void ConfigureOpenTelemetry(RuntimeConfig runtimeConfig) return; } - if (string.IsNullOrWhiteSpace(OpenTelemetryOptions?.Endpoint)) + if (string.IsNullOrWhiteSpace(OpenTelemetryOptions?.Endpoint) + || !Uri.TryCreate(OpenTelemetryOptions.Endpoint, UriKind.Absolute, out _)) { - _logger.LogWarning("Logs won't be sent to Open Telemetry because an Open Telemetry connection string is not available in the runtime config."); + _logger.LogWarning("Logs won't be sent to Open Telemetry because a valid Open Telemetry endpoint URI is not available in the runtime config."); return; }