-
Notifications
You must be signed in to change notification settings - Fork 292
Add support for Open Telemetry #2449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
8f02203
working otel exporter configured via dab-config.json
tommasodotNET f7160fd
set default value for otel service name to dab
tommasodotNET 00caf7c
readded nuget config
tommasodotNET fe5518b
removes unnecessary code for otel
tommasodotNET c72e7b2
adds unit tests
tommasodotNET a35fe37
reorder traces
tommasodotNET 74d2691
Merge branch 'main' into 2397-otel
tommasodotNET f904d76
default value name for otel service name in schema
tommasodotNET e44dceb
net8 specifc nugets in their own item group
tommasodotNET eacfce3
fixes syntax
tommasodotNET aed41fd
configurable otel protocol
tommasodotNET 2528012
adding comments on tests
tommasodotNET 59d6e5a
adds tests for open telemetry
tommasodotNET 0341cb4
renames OtlpExportProtocol to ExporterProtocol
tommasodotNET c9bb417
exporter-protocol in dab draft schema
tommasodotNET 1dd53e8
fixes formatting on usings
tommasodotNET 8fdbf50
fixes if formatting
tommasodotNET 96fa415
fix formatting
abhishekkumams 2a2d591
fix formatting
abhishekkumams d06ca3b
Merge branch 'main' into 2397-otel
abhishekkumams fa5dc01
Update src/Cli/Commands/AddTelemetryOptions.cs
tommasodotNET 9b73458
Update src/Cli/Commands/AddTelemetryOptions.cs
tommasodotNET c632865
appin-cs and otelendpoint not required by default
tommasodotNET c2b1c19
Merge branch '2397-otel' of https://github.com/tommasodotNET/data-api…
tommasodotNET 4769896
fixes otelExProtocol
tommasodotNET 1eeea23
fixes OpenTelemetryExportProtocol
tommasodotNET 90d6884
Merge branch 'main' into 2397-otel
tommasodotNET 2033f71
removes target build conditions
tommasodotNET acb3d7b
fix formatting
abhishekkumams f6f3209
Merge branch 'main' into 2397-otel
abhishekkumams d20cab1
fix parameters odering
abhishekkumams 66f765a
Merge branch 'main' into 2397-otel
abhishekkumams cd39019
fix test
abhishekkumams e84b1a8
Merge branch '2397-otel' of https://github.com/tommasodotNET/data-api…
abhishekkumams 52a8a6c
fix test
abhishekkumams 20e824f
adds headers to addopenttelemetrytests
tommasodotNET c7d6f29
fixes correct required param for otel
tommasodotNET d3e3030
Merge branch '2397-otel' of https://github.com/tommasodotNET/data-api…
tommasodotNET 88c01cf
adds license in oteloptions and tests
tommasodotNET 3a4e330
specifies SetUpTelemetryInConfig is a helper function
tommasodotNET 9727827
adds check file exists before deleting in oteltests
tommasodotNET 5220a51
fixes AddTelemetryOptions cli help texts and comments
tommasodotNET db3dbbe
specifies params in AddTelemetryTests
tommasodotNET File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Cli.Tests | ||
| { | ||
| /// <summary> | ||
| /// Tests for verifying the functionality of adding OpenTelemetry to the config file. | ||
| /// </summary> | ||
| [TestClass] | ||
| public class AddOpenTelemetryTests | ||
| { | ||
| public string RUNTIME_SECTION_WITH_OPEN_TELEMETRY_SECTION = GenerateRuntimeSection(TELEMETRY_SECTION_WITH_OPEN_TELEMETRY); | ||
| public string RUNTIME_SECTION_WITH_EMPTY_TELEMETRY_SECTION = GenerateRuntimeSection(EMPTY_TELEMETRY_SECTION); | ||
| [TestInitialize] | ||
| public void TestInitialize() | ||
| { | ||
| ILoggerFactory loggerFactory = TestLoggerSupport.ProvisionLoggerFactory(); | ||
|
|
||
| ConfigGenerator.SetLoggerForCliConfigGenerator(loggerFactory.CreateLogger<ConfigGenerator>()); | ||
| Utils.SetCliUtilsLogger(loggerFactory.CreateLogger<Utils>()); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Testing to check OpenTelemetry options are correctly added to the config. | ||
| /// Verifying scenarios such as enabling/disabling OpenTelemetry and providing a valid/empty endpoint. | ||
| /// </summary> | ||
| [DataTestMethod] | ||
| [DataRow(CliBool.True, "", false, DisplayName = "Fail to add OpenTelemetry with empty endpoint.")] | ||
| [DataRow(CliBool.True, "http://localhost:4317", true, DisplayName = "Successfully adds OpenTelemetry with valid endpoint")] | ||
| [DataRow(CliBool.False, "http://localhost:4317", true, DisplayName = "Successfully adds OpenTelemetry but disabled")] | ||
| public void TestAddOpenTelemetry(CliBool isTelemetryEnabled, string endpoint, bool expectSuccess) | ||
| { | ||
| MockFileSystem fileSystem = FileSystemUtils.ProvisionMockFileSystem(); | ||
| string configPath = "test-opentelemetry-config.json"; | ||
| fileSystem.AddFile(configPath, new MockFileData(INITIAL_CONFIG)); | ||
|
|
||
| // Initial State | ||
| Assert.IsTrue(fileSystem.FileExists(configPath)); | ||
| Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(fileSystem.File.ReadAllText(configPath), out RuntimeConfig? config)); | ||
| Assert.IsNotNull(config); | ||
| Assert.IsNotNull(config.Runtime); | ||
| Assert.IsNull(config.Runtime.Telemetry); | ||
|
|
||
| // Add OpenTelemetry | ||
| bool isSuccess = ConfigGenerator.TryAddTelemetry( | ||
| new AddTelemetryOptions(openTelemetryEndpoint: endpoint, openTelemetryEnabled: isTelemetryEnabled, config: configPath), | ||
| new FileSystemRuntimeConfigLoader(fileSystem), | ||
| fileSystem); | ||
|
|
||
| // Assert after adding OpenTelemetry | ||
| Assert.AreEqual(expectSuccess, isSuccess); | ||
| if (expectSuccess) | ||
| { | ||
| Assert.IsTrue(fileSystem.FileExists(configPath)); | ||
| Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(fileSystem.File.ReadAllText(configPath), out config)); | ||
| Assert.IsNotNull(config); | ||
| Assert.IsNotNull(config.Runtime); | ||
| Assert.IsNotNull(config.Runtime.Telemetry); | ||
| TelemetryOptions telemetryOptions = config.Runtime.Telemetry; | ||
| Assert.IsNotNull(telemetryOptions.OpenTelemetry); | ||
| Assert.AreEqual(isTelemetryEnabled is CliBool.True ? true : false, telemetryOptions.OpenTelemetry.Enabled); | ||
| Assert.AreEqual(endpoint, telemetryOptions.OpenTelemetry.Endpoint); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test to verify when Telemetry section is present in the config | ||
| /// It should add OpenTelemetry if telemetry section is empty | ||
| /// or overwrite the existing OpenTelemetry with the given OpenTelemetry options. | ||
| /// </summary> | ||
| [DataTestMethod] | ||
| [DataRow(true, DisplayName = "Add OpenTelemetry when telemetry section is empty.")] | ||
| [DataRow(false, DisplayName = "Overwrite OpenTelemetry when telemetry section already exists.")] | ||
| public void TestAddOpenTelemetryWhenTelemetryAlreadyExists(bool isEmptyTelemetry) | ||
| { | ||
| MockFileSystem fileSystem = FileSystemUtils.ProvisionMockFileSystem(); | ||
| string configPath = "test-opentelemetry-config.json"; | ||
| string runtimeSection = isEmptyTelemetry ? RUNTIME_SECTION_WITH_EMPTY_TELEMETRY_SECTION : RUNTIME_SECTION_WITH_OPEN_TELEMETRY_SECTION; | ||
| string configData = $"{{{SAMPLE_SCHEMA_DATA_SOURCE},{runtimeSection}}}"; | ||
| fileSystem.AddFile(configPath, new MockFileData(configData)); | ||
|
|
||
| // Initial State | ||
| Assert.IsTrue(fileSystem.FileExists(configPath)); | ||
| Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(fileSystem.File.ReadAllText(configPath), out RuntimeConfig? config)); | ||
| Assert.IsNotNull(config); | ||
| Assert.IsNotNull(config.Runtime); | ||
| Assert.IsNotNull(config.Runtime.Telemetry); | ||
|
|
||
| if (isEmptyTelemetry) | ||
| { | ||
| Assert.IsNull(config.Runtime.Telemetry.OpenTelemetry); | ||
| } | ||
| else | ||
| { | ||
| Assert.IsNotNull(config.Runtime.Telemetry.OpenTelemetry); | ||
| Assert.AreEqual(true, config.Runtime.Telemetry.OpenTelemetry.Enabled); | ||
| Assert.AreEqual("http://localhost:4317", config.Runtime.Telemetry.OpenTelemetry.Endpoint); | ||
| } | ||
|
|
||
| // Add OpenTelemetry | ||
| bool isSuccess = ConfigGenerator.TryAddTelemetry( | ||
| new AddTelemetryOptions(openTelemetryEndpoint: "http://localhost:4318", openTelemetryEnabled: CliBool.False, config: configPath), | ||
| new FileSystemRuntimeConfigLoader(fileSystem), | ||
| fileSystem); | ||
|
|
||
| // Assert after adding OpenTelemetry | ||
| Assert.IsTrue(isSuccess); | ||
| Assert.IsTrue(fileSystem.FileExists(configPath)); | ||
| Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(fileSystem.File.ReadAllText(configPath), out config)); | ||
| Assert.IsNotNull(config); | ||
| Assert.IsNotNull(config.Runtime); | ||
| Assert.IsNotNull(config.Runtime.Telemetry); | ||
| Assert.IsNotNull(config.Runtime.Telemetry.OpenTelemetry); | ||
| Assert.IsFalse(config.Runtime.Telemetry.OpenTelemetry.Enabled); | ||
| Assert.AreEqual("http://localhost:4318", config.Runtime.Telemetry.OpenTelemetry.Endpoint); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Generates a JSON string representing a runtime section of the config, with a customizable telemetry section. | ||
| /// </summary> | ||
| private static string GenerateRuntimeSection(string telemetrySection) | ||
| { | ||
| return $@" | ||
| ""runtime"": {{ | ||
| ""rest"": {{ | ||
| ""path"": ""/api"", | ||
| ""enabled"": false | ||
| }}, | ||
| ""graphql"": {{ | ||
| ""path"": ""/graphql"", | ||
| ""enabled"": false, | ||
| ""allow-introspection"": true | ||
| }}, | ||
| ""host"": {{ | ||
| ""mode"": ""development"", | ||
| ""cors"": {{ | ||
| ""origins"": [], | ||
| ""allow-credentials"": false | ||
| }}, | ||
| ""authentication"": {{ | ||
| ""provider"": ""StaticWebApps"" | ||
| }} | ||
| }}, | ||
| {telemetrySection} | ||
| }}, | ||
| ""entities"": {{}}"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents a JSON string for the telemetry section of the config, with Application Insights enabled and a specified connection string. | ||
| /// </summary> | ||
| private const string TELEMETRY_SECTION_WITH_OPEN_TELEMETRY = @" | ||
| ""telemetry"": { | ||
| ""open-telemetry"": { | ||
| ""enabled"": true, | ||
| ""endpoint"": ""http://localhost:4317"" | ||
| } | ||
| }"; | ||
|
|
||
| /// <summary> | ||
| /// Represents a JSON string for the empty telemetry section of the config. | ||
| /// </summary> | ||
| private const string EMPTY_TELEMETRY_SECTION = @" | ||
| ""telemetry"": {}"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using OpenTelemetry.Exporter; | ||
tommasodotNET marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| namespace Azure.DataApiBuilder.Config.ObjectModel; | ||
|
|
||
| /// <summary> | ||
| /// Represents the options for configuring Open Telemetry. | ||
| /// </summary> | ||
| public record OpenTelemetryOptions(bool Enabled = false, string? Endpoint = null, string? Headers = null, OtlpExportProtocol? ExporterProtocol = null, string? ServiceName = null) | ||
| { } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.