Skip to content
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

OpenTelemetry 支持添加 Headers #183

Merged
merged 1 commit into from
Jul 16, 2024
Merged
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
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
Loading