Skip to content

Commit

Permalink
OpenTelemetry 支持添加 Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
pengqian089 committed Jul 15, 2024
1 parent aceb62f commit 7df0dfa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/AgileConfig.Server.Apisite/Appsettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,22 @@ public class Appsettings

public static string OtlpLogsEndpoint => Global.Config["otlp:logs:endpoint"];

public static string OtlpLogsHeaders => Global.Config["otlp:logs:headers"];

public static string OtlpLogsProtocol => Global.Config["otlp:logs:protocol"];

public static string OtlpTracesEndpoint => Global.Config["otlp:traces:endpoint"];

public static string OtlpTracesProtocol => Global.Config["otlp:traces:protocol"];

public static string OtlpTracesHeaders => Global.Config["otlp:traces:headers"];

public static string OtlpMetricsEndpoint => Global.Config["otlp:metrics:endpoint"];

public static string OtlpMetricsProtocol => Global.Config["otlp:metrics:protocol"];

public static string OtlpMetricsHeaders => Global.Config["otlp:metrics:headers"];

public static string OtlpInstanceId => Global.Config["otlp:instanceId"];

}
Expand Down
7 changes: 5 additions & 2 deletions src/AgileConfig.Server.Apisite/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ private static void AddOtlpLogging(ILoggingBuilder builder)
{
expOp.Protocol = Appsettings.OtlpLogsProtocol == "http" ? OtlpExportProtocol.HttpProtobuf : OtlpExportProtocol.Grpc;
expOp.Endpoint = new Uri(Appsettings.OtlpLogsEndpoint);
})
;
if (!string.IsNullOrEmpty(Appsettings.OtlpLogsHeaders))
{
expOp.Headers = Appsettings.OtlpLogsHeaders;
}
});
});
}

Expand Down
8 changes: 8 additions & 0 deletions src/AgileConfig.Server.Apisite/StartupExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public static IOpenTelemetryBuilder AddOtlpTraces(this IOpenTelemetryBuilder bui
{
op.Protocol = Appsettings.OtlpTracesProtocol == "http" ? OtlpExportProtocol.HttpProtobuf : OtlpExportProtocol.Grpc;
op.Endpoint = new System.Uri(Appsettings.OtlpTracesEndpoint);
if (!string.IsNullOrEmpty(Appsettings.OtlpTracesHeaders))
{
op.Headers = Appsettings.OtlpTracesHeaders;
}
})
);

Expand All @@ -59,6 +63,10 @@ public static IOpenTelemetryBuilder AddOtlpMetrics(this IOpenTelemetryBuilder bu
op.Protocol = Appsettings.OtlpMetricsProtocol == "http" ? OtlpExportProtocol.HttpProtobuf : OtlpExportProtocol.Grpc;
op.Endpoint = new System.Uri(Appsettings.OtlpMetricsEndpoint);
reader.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 1000;
if (!string.IsNullOrEmpty(Appsettings.OtlpMetricsHeaders))
{
op.Headers = Appsettings.OtlpMetricsHeaders;
}
})
);

Expand Down
9 changes: 6 additions & 3 deletions src/AgileConfig.Server.Apisite/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
"instanceId": "agileconfig server -1", // if empty, will generate a new one
"logs": {
"protocol": "http", // http grpc
"endpoint": "http://192.168.0.201:5341/ingest/otlp/v1/logs"
"endpoint": "http://192.168.0.201:5341/ingest/otlp/v1/logs",
"headers":"X-Seq-ApiKey=aabbcc,X-Other-Head=other_head"
},
"traces": {
"protocol": "http", // http grpc
"endpoint": "http://192.168.0.201:5341/ingest/otlp/v1/traces"
"endpoint": "http://192.168.0.201:5341/ingest/otlp/v1/traces",
"headers":"X-Seq-ApiKey=aabbcc"
},
"metrics": {
"protocol": "http", // http grpc
"endpoint": "http://localhost:9090/api/v1/otlp/v1/metrics"
"endpoint": "http://localhost:9090/api/v1/otlp/v1/metrics",
"headers":"X-Seq-ApiKey=aabbcc"
}
},
"alwaysTrustSsl": true, // If true, the server will ignore SSL errors.
Expand Down

0 comments on commit 7df0dfa

Please sign in to comment.