Skip to content

Commit eb712fb

Browse files
committed
Add TenantId CorrelationId to Loki
1 parent aef324e commit eb712fb

3 files changed

Lines changed: 47 additions & 12 deletions

File tree

src/plugins/SerilogTest/Program.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.AspNetCore.HttpLogging;
2+
using Microsoft.AspNetCore.HttpOverrides;
23
using Serilog;
34
using Serilog.Core;
45
using Serilog.Exceptions;
@@ -75,7 +76,15 @@ private static async Task Main(string[] args)
7576

7677
var app = builder.Build();
7778

78-
_ = app.UseForwardedHeaders();
79+
var forwardOptions = new ForwardedHeadersOptions
80+
{
81+
ForwardedHeaders = ForwardedHeaders.All,
82+
ForwardLimit = null
83+
};
84+
//forwardOptions.KnownProxies.Add(new IPAddress(0L));
85+
//forwardOptions.KnownNetworks.Add(new Microsoft.AspNetCore.HttpOverrides.IPNetwork(new IPAddress(0L), 0));
86+
87+
_ = app.UseForwardedHeaders(forwardOptions);
7988
_ = app.UseHttpsRedirection();
8089

8190
_ = app.UseStaticFiles();

src/plugins/SerilogTest/SerilogTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
2424
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.4" />
2525
<PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="8.3.0" />
26+
<PackageReference Include="Serilog.Sinks.Loki.YetAnother" Version="3.0.7" />
2627
</ItemGroup>
2728

2829
<ItemGroup>

src/plugins/SerilogTest/appsettings.json

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,45 @@
5757
]
5858
}
5959
},
60+
//{
61+
// "Name": "GrafanaLoki",
62+
// "Args": {
63+
// "uri": "http://localhost:3100",
64+
// "period": "00:00:05",
65+
// "labels": [
66+
// {
67+
// "key": "service_name",
68+
// "value": "SerilogTest"
69+
// }
70+
// ],
71+
// "propertiesAsLabels": [
72+
// "EnvironmentName"
73+
// ]
74+
// }
75+
//},
6076
{
61-
"Name": "GrafanaLoki",
77+
"Name": "Loki",
6278
"Args": {
63-
"uri": "http://localhost:3100",
79+
"configurations": {
80+
"Url": "http://localhost:3100",
81+
//"Credentials": {
82+
// "Password": "password",
83+
// "Username": "username"
84+
//},
85+
"Labels": [
86+
{
87+
"key": "service_name",
88+
"value": "SerilogTest"
89+
}
90+
],
91+
"PropertiesAsLabels": [
92+
"EnvironmentName"
93+
],
94+
"EnrichTraceId": true,
95+
"EnrichSpanId": true
96+
},
6497
"period": "00:00:05",
65-
"labels": [
66-
{
67-
"key": "service_name",
68-
"value": "SerilogTest"
69-
}
70-
],
71-
"propertiesAsLabels": [
72-
"EnvironmentName"
73-
]
98+
"retryTimeLimit": "00:10:00"
7499
}
75100
}
76101
]

0 commit comments

Comments
 (0)