Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs-builder.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=frontmatter/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=linenos/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=literalinclude/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Otlp/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0060_0060inli/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
13 changes: 5 additions & 8 deletions src/Elastic.Documentation.ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where

public static TBuilder AddOpenTelemetryDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{

var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
if (!useOtlpExporter)
return builder;

_ = builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeFormattedMessage = true;
Expand Down Expand Up @@ -86,14 +91,6 @@ private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builde

_ = builder.Services.AddOpenTelemetry().UseOtlpExporter();
}

// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
//{
// builder.Services.AddOpenTelemetry()
// .UseAzureMonitor();
//}

return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ namespace Elastic.Documentation.Api.Infrastructure;

public static class MappingsExtension
{
public static void MapElasticDocsApiEndpoints(this IEndpointRouteBuilder group)
public static void MapElasticDocsApiEndpoints(this IEndpointRouteBuilder group, bool mapOtlpEndpoints = true)
{

_ = group.MapGet("/", () => Results.Empty);
_ = group.MapPost("/", () => Results.Empty);
MapAskAiEndpoint(group);
MapNavigationSearch(group);
MapOtlpProxyEndpoint(group);
if (mapOtlpEndpoints)
MapOtlpProxyEndpoint(group);
}

private static void MapAskAiEndpoint(IEndpointRouteBuilder group)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ public static TracerProviderBuilder AddDocsApiTracing(this TracerProviderBuilder
/// </summary>
/// <param name="builder">The web application builder</param>
/// <returns>The builder for chaining</returns>
public static TBuilder AddDocsApiOpenTelemetry<TBuilder>(
this TBuilder builder)
public static TBuilder AddDocsApiOpenTelemetry<TBuilder>(this TBuilder builder)
where TBuilder : IHostApplicationBuilder
{
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
if (!useOtlpExporter)
return builder;

var options = new ElasticOpenTelemetryOptions
{
// In AOT mode, assembly scanning is not supported, so we skip it
Expand Down
4 changes: 3 additions & 1 deletion src/api/Elastic.Documentation.Api.Lambda/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
_ = app.UseDeveloperExceptionPage();

var v1 = app.MapGroup("/docs/_api/v1");
v1.MapElasticDocsApiEndpoints();

var mapOtlpEndpoints = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
v1.MapElasticDocsApiEndpoints(mapOtlpEndpoints);
Console.WriteLine("API endpoints mapped");

Console.WriteLine("Application startup completed successfully");
Expand Down
3 changes: 2 additions & 1 deletion src/tooling/docs-builder/Http/DocumentationWebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ private void SetUpRoutes()

var apiV1 = _webApplication.MapGroup("/docs/_api/v1");
#if DEBUG
apiV1.MapElasticDocsApiEndpoints();
var mapOtlpEndpoints = !string.IsNullOrWhiteSpace(_webApplication.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
apiV1.MapElasticDocsApiEndpoints(mapOtlpEndpoints);
#endif

_ = _webApplication.MapGet("{**slug}", (string slug, ReloadableGeneratorState holder, Cancel ctx) =>
Expand Down
3 changes: 2 additions & 1 deletion src/tooling/docs-builder/Http/StaticWebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ private void SetUpRoutes()

var apiV1 = WebApplication.MapGroup("/docs/_api/v1");
#if DEBUG
apiV1.MapElasticDocsApiEndpoints();
var mapOtlpEndpoints = !string.IsNullOrWhiteSpace(WebApplication.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
apiV1.MapElasticDocsApiEndpoints(mapOtlpEndpoints);
#endif

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,23 @@ namespace Elastic.Documentation.Api.IntegrationTests;
/// Integration tests for euid cookie enrichment in OpenTelemetry traces and logging.
/// Uses WebApplicationFactory to test the real API configuration with mocked AskAi services.
/// </summary>
public class EuidEnrichmentIntegrationTests
public class EuidEnrichmentIntegrationTests : IAsyncLifetime
{
private const string OtlpEndpoint = "http://localhost:4318";

public ValueTask InitializeAsync()
{
Environment.SetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", OtlpEndpoint);
return ValueTask.CompletedTask;
}

public ValueTask DisposeAsync()
{
GC.SuppressFinalize(this);
Environment.SetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", null);
return ValueTask.CompletedTask;
}

/// <summary>
/// Test that verifies euid cookie is added to both HTTP span and custom AskAi span,
/// and appears in log entries - using the real API configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@

namespace Elastic.Documentation.Api.IntegrationTests;

public class OtlpProxyIntegrationTests
public class OtlpProxyIntegrationTests : IAsyncLifetime
{
private const string OtlpEndpoint = "http://localhost:4318";

public ValueTask InitializeAsync()
{
Environment.SetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", OtlpEndpoint);
return ValueTask.CompletedTask;
}

public ValueTask DisposeAsync()
{
GC.SuppressFinalize(this);
Environment.SetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", null);
return ValueTask.CompletedTask;
}

[Fact]
public async Task OtlpProxyTracesEndpointForwardsToCorrectUrl()
{
Expand Down Expand Up @@ -71,7 +86,7 @@ public async Task OtlpProxyTracesEndpointForwardsToCorrectUrl()
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
capturedRequest.Should().NotBeNull();
capturedRequest!.RequestUri.Should().NotBeNull();
capturedRequest.RequestUri!.ToString().Should().Be("http://localhost:4318/v1/traces");
capturedRequest.RequestUri!.ToString().Should().Be($"{OtlpEndpoint}/v1/traces");
capturedRequest.Method.Should().Be(HttpMethod.Post);
capturedRequest.Content.Should().NotBeNull();
capturedRequest.Content!.Headers.ContentType!.MediaType.Should().Be("application/json");
Expand Down Expand Up @@ -131,7 +146,7 @@ public async Task OtlpProxyLogsEndpointForwardsToCorrectUrl()
// Assert - verify the enum ToStringFast() generates "logs" (lowercase)
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
capturedRequest.Should().NotBeNull();
capturedRequest!.RequestUri!.ToString().Should().Be("http://localhost:4318/v1/logs");
capturedRequest!.RequestUri!.ToString().Should().Be($"{OtlpEndpoint}/v1/logs");

// Cleanup mock response
mockResponse.Dispose();
Expand Down Expand Up @@ -184,7 +199,7 @@ public async Task OtlpProxyMetricsEndpointForwardsToCorrectUrl()
// Assert - verify the enum ToStringFast() generates "metrics" (lowercase)
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
capturedRequest.Should().NotBeNull();
capturedRequest!.RequestUri!.ToString().Should().Be("http://localhost:4318/v1/metrics");
capturedRequest!.RequestUri!.ToString().Should().Be($"{OtlpEndpoint}/v1/metrics");

// Cleanup mock response
mockResponse.Dispose();
Expand Down
Loading