Skip to content

Commit 0829fea

Browse files
committed
Initial commit
1 parent a559b64 commit 0829fea

19 files changed

+244
-195
lines changed

Dockerfile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
# 請參閱 https://aka.ms/customizecontainer 了解如何自訂您的偵錯容器,以及 Visual Studio 如何使用此 Dockerfile 來組建您的映像,以加快偵錯速度。
1+
# 請參閱 https://aka.ms/customizecontainer 了解如何自訂您的偵錯容器,以及 Visual Studio 如何使用此 Dockerfile 來組建您的映像,以加快偵錯速度。
22

33
# 此階段用於以快速模式從 VS 執行時 (偵錯設定的預設值)
4-
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
5-
USER app
4+
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
5+
USER $APP_UID
66
WORKDIR /app
77
EXPOSE 8080
88
EXPOSE 8081
99

1010

1111
# 此階段是用來組建服務專案
12-
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
12+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
1313
ARG BUILD_CONFIGURATION=Release
1414
WORKDIR /src
15-
COPY ["OpenTelemetrySample.AppHost/OpenTelemetrySample.AppHost.csproj", "OpenTelemetrySample.AppHost/"]
16-
RUN dotnet restore "./OpenTelemetrySample.AppHost/OpenTelemetrySample.AppHost.csproj"
15+
COPY ["src/GHLearning.OpenTelemetrySample/GHLearning.OpenTelemetrySample.csproj", "src/GHLearning.OpenTelemetrySample/"]
16+
RUN dotnet restore "./src/GHLearning.OpenTelemetrySample/GHLearning.OpenTelemetrySample.csproj"
1717
COPY . .
18-
WORKDIR "/src/OpenTelemetrySample.AppHost"
19-
RUN dotnet build "./OpenTelemetrySample.AppHost.csproj" -c $BUILD_CONFIGURATION -o /app/build
18+
WORKDIR "/src/src/GHLearning.OpenTelemetrySample"
19+
RUN dotnet build "./GHLearning.OpenTelemetrySample.csproj" -c $BUILD_CONFIGURATION -o /app/build
2020

2121
# 此階段可用來發佈要複製到最終階段的服務專案
2222
FROM build AS publish
2323
ARG BUILD_CONFIGURATION=Release
24-
RUN dotnet publish "./OpenTelemetrySample.AppHost.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
24+
RUN dotnet publish "./GHLearning.OpenTelemetrySample.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
2525

2626
# 此階段用於生產環境,或以一般模式從 VS 執行時 (未使用偵錯設定時的預設值)
2727
FROM base AS final
2828
WORKDIR /app
2929
COPY --from=publish /app/publish .
30-
ENTRYPOINT ["dotnet", "OpenTelemetrySample.AppHost.dll"]
30+
ENTRYPOINT ["dotnet", "GHLearning.OpenTelemetrySample.dll"]

GHLearning.OpenTelemetry.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.11.35431.28
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GHLearning.OpenTelemetrySample", "src\GHLearning.OpenTelemetrySample\GHLearning.OpenTelemetrySample.csproj", "{A7EBA9BC-01A1-74A6-C37A-DC56C4FF2F47}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{A7EBA9BC-01A1-74A6-C37A-DC56C4FF2F47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{A7EBA9BC-01A1-74A6-C37A-DC56C4FF2F47}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{A7EBA9BC-01A1-74A6-C37A-DC56C4FF2F47}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{A7EBA9BC-01A1-74A6-C37A-DC56C4FF2F47}.Release|Any CPU.Build.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(NestedProjects) = preSolution
25+
{A7EBA9BC-01A1-74A6-C37A-DC56C4FF2F47} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
26+
EndGlobalSection
27+
GlobalSection(ExtensibilityGlobals) = postSolution
28+
SolutionGuid = {EC6F32B7-BA86-41F1-98A9-3B69554D8C75}
29+
EndGlobalSection
30+
EndGlobal

OpenTelemetrySample.AppHost/OpenTelemetrySample.AppHost.http

Lines changed: 0 additions & 6 deletions
This file was deleted.

OpenTelemetrySample.AppHost/Program.cs

Lines changed: 0 additions & 83 deletions
This file was deleted.

OpenTelemetrySample.AppHost/Properties/launchSettings.json

Lines changed: 0 additions & 51 deletions
This file was deleted.

OpenTelemetrySample.sln

Lines changed: 0 additions & 25 deletions
This file was deleted.

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ services:
77
dockerfile: Dockerfile
88
container_name: sample-app
99
environment:
10-
- ASPNETCORE_ENVIRONMENT=Development
11-
- OTLP_ENDPOINT_URL=http://otel-collector:4317/
12-
- SERVICE_NAME=OpenTelemetrySample-Api
10+
- ASPNETCORE_ENVIRONMENT=Production
1311
ports:
1412
- 8080:8080
1513
networks:
@@ -40,6 +38,8 @@ services:
4038
- ./otel-collector/otel-collector-config.yaml:/etc/otel-collector-config.yaml:ro
4139
ports:
4240
- "4317:4317" # OTLP gRPC receiver
41+
- "8888:8888" # internal metrics
42+
- "8889:8889" # OTLP metrics
4343
networks:
4444
- sample-nat
4545
restart: unless-stopped

otel-collector/otel-collector-config.yaml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,47 @@ receivers:
55
endpoint: 0.0.0.0:4317
66
http:
77
endpoint: 0.0.0.0:4318
8+
89
fluentforward:
910
endpoint: 0.0.0.0:24224
1011

12+
prometheus/otelcol:
13+
config:
14+
scrape_configs:
15+
- job_name: 'otelcol'
16+
scrape_interval: 10s
17+
static_configs:
18+
- targets: ['0.0.0.0:8888']
19+
1120
exporters:
1221
prometheus:
13-
endpoint: "0.0.0.0:9090"
22+
endpoint: 0.0.0.0:8889
1423
const_labels:
1524
label1: value1
25+
1626
otlp:
1727
endpoint: jaeger-collector:4317
1828
tls:
1929
insecure: true
30+
2031
otlphttp/sep:
2132
endpoint: "http://seq:5341/ingest/otlp/"
22-
headers:
23-
api-key: "X-Seq-ApiKey: p6FrUTYwLz6qakVqRctT"
2433
tls:
2534
insecure: true
35+
2636
otlphttp/loki:
2737
endpoint: "http://loki:3100/otlp/"
2838
tls:
2939
insecure: true
40+
3041
elasticsearch:
3142
endpoint: "http://elasticsearch:9200"
3243
index: "otel-logs"
44+
3345
otlphttp/fluentd:
3446
endpoint: "http://fluentbit:4318" # Fluent Bit 的接收端口
3547
timeout: 10s
48+
3649
processors:
3750
batch:
3851

@@ -43,15 +56,18 @@ extensions:
4356

4457
service:
4558
extensions: [pprof, health_check]
59+
telemetry:
60+
metrics:
61+
address: 0.0.0.0:8888
4662
pipelines:
4763
traces:
4864
receivers: [otlp]
4965
processors: [batch]
5066
exporters: [otlp]
5167
metrics:
52-
receivers: [otlp]
68+
receivers: [prometheus/otelcol,otlp]
5369
processors: [batch]
54-
exporters: [ prometheus]
70+
exporters: [prometheus]
5571
logs:
5672
receivers: [otlp,fluentforward]
5773
processors: [batch]

prometheus/prometheus.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ scrape_configs:
55
- job_name: prometheus
66
static_configs:
77
- targets: ["localhost:9090"]
8-
- job_name: 'otel-collector'
8+
- job_name: 'otel-collector-metrics'
99
static_configs:
10-
- targets: ['otel-collector:9090']
10+
- targets: ['otel-collector:8889']
1111
- job_name: 'cadvisor'
1212
static_configs:
1313
- targets: ['cadvisor:8080']
1414
- job_name: 'node'
1515
static_configs:
16-
- targets: ['node-exporter:9100']
16+
- targets: ['node-exporter:9100']
17+
- job_name: 'app'
18+
static_configs:
19+
- targets: ['app:8080']

OpenTelemetrySample.AppHost/Controllers/InfoController.cs renamed to src/GHLearning.OpenTelemetrySample/Controllers/InfoController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Reflection;
44
using Microsoft.AspNetCore.Mvc;
55

6-
namespace OpenTelemetrySample.AppHost.Controllers;
6+
namespace GHLearning.OpenTelemetrySample.Controllers;
77

88
[ApiController]
99
[Route("api/[controller]")]
@@ -37,8 +37,8 @@ public async Task<object> GetAsync(
3737
AspnetcoreHttpsPorts = configuration["ASPNETCORE_HTTPS_PORTS"],
3838
AspnetcoreHttpPorts = configuration["ASPNETCORE_HTTP_PORTS"],
3939
AspnetcoreEnvironment = configuration["ASPNETCORE_ENVIRONMENT"],
40-
OtlpEndpointUrl = configuration["OTLP_ENDPOINT_URL"],
41-
ServiceName = configuration["SERVICE_NAME"]
40+
OtlpEndpointUrl = configuration.GetValue<string>("OtlpEndpointUrl"),
41+
ServiceName = configuration.GetValue<string>("ServiceName")
4242
};
4343
}
4444
}

0 commit comments

Comments
 (0)