Skip to content

Commit 040940d

Browse files
committed
Instrument Docker Compose setups to enable Application Observability
1 parent 62cf0f8 commit 040940d

File tree

7 files changed

+58
-19
lines changed

7 files changed

+58
-19
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,19 @@ Now, you can log in to [Grafana Cloud](https://grafana.com/products/cloud/) and
173173

174174
To find the labels applied to the telemetry data, refer to [cloud.alloy](./alloy/cloud.alloy) and [docker-compose-cloud.yaml](./docker-compose-cloud.yaml) .
175175

176-
### Monitor frontend with Grafana Cloud Frontend Observability
176+
### Monitor QuickPizza with Grafana Cloud Application Observability and Frontend Observability
177177

178-
To enable [Grafana Cloud Frontend Observability](https://grafana.com/docs/grafana-cloud/monitor-applications/frontend-observability/) for QuickPizza:
178+
The Docker Compose setup is fully instrumented out of the box, so you can jump right into Grafana Cloud Observability apps and start observing the inner workings of the QuickPizza service components.
179+
180+
To enable [Grafana Cloud Application Observability](https://grafana.com/docs/grafana-cloud/monitor-applications/application-observability/) for QuickPizza:
181+
182+
1. In your Grafana Cloud instance, navigate to **Observability > Application**.
183+
2. Click on **Enable metrics generation** to enable the usage of Application Observability.
184+
3. Interact with the QuickPizza app to generate traffic. After a few minutes, the QuickPizza components will be automatically discovered and displayed in the UI.
185+
186+
![Application Observability](./docs/images/grafana-cloud-application-application-observability-quickpizza.png)
187+
188+
To enable [Grafana Cloud Frontend Observability](https://grafana.com/docs/grafana-cloud/monitor-applications/frontend-observability/):
179189

180190
1. In Grafana Cloud, create a new Frontend Observability application and set the domain to `http://localhost:3333`.
181191
2. Copy the application's Faro web URL.

alloy/cloud.alloy

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,30 @@ otelcol.receiver.otlp "default" {
99
}
1010

1111
output {
12-
traces = [otelcol.processor.batch.default.input]
12+
traces = [
13+
otelcol.processor.batch.default.input,
14+
otelcol.connector.host_info.default.input,
15+
]
16+
}
17+
}
18+
19+
otelcol.connector.host_info "default" {
20+
host_identifiers = ["container.name", "container.id", "service.name"]
21+
metrics_flush_interval = "10s"
22+
23+
output {
24+
metrics = [otelcol.exporter.prometheus.otlp_metrics.input]
1325
}
1426
}
27+
otelcol.exporter.prometheus "otlp_metrics" {
28+
forward_to = [
29+
grafana_cloud.stack.receivers.metrics,
30+
]
31+
}
1532

1633
otelcol.processor.batch "default" {
1734
output {
18-
metrics = []
19-
logs = []
20-
traces = [
21-
grafana_cloud.stack.receivers.traces,
22-
]
35+
traces = [grafana_cloud.stack.receivers.traces]
2336
}
2437
}
2538

@@ -33,6 +46,8 @@ prometheus.scrape "default" {
3346
"__address__" = env("QUICKPIZZA_HOST"),
3447
"job" = "quickpizza",
3548
"instance" = "local",
49+
"service_name" = "quickpizza",
50+
"service_namespace" = "quickpizza",
3651
},
3752
]
3853
}
@@ -65,6 +80,10 @@ loki.source.docker "default" {
6580
host = "unix:///var/run/docker.sock"
6681
targets = discovery.relabel.quickpizza.output
6782
forward_to = [grafana_cloud.stack.receivers.logs]
83+
labels = {
84+
service_name = "quickpizza",
85+
service_namespace = "quickpizza",
86+
}
6887
}
6988

7089
import.git "grafana_cloud" {

alloy/local.alloy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ prometheus.scrape "default" {
3333
"__address__" = env("QUICKPIZZA_HOST"),
3434
"job" = "quickpizza",
3535
"instance" = "local",
36+
"service_name" = "quickpizza",
37+
"service_namespace" = "quickpizza",
3638
},
3739
]
3840
}
@@ -86,6 +88,10 @@ loki.source.docker "default" {
8688
host = "unix:///var/run/docker.sock"
8789
targets = discovery.relabel.quickpizza.output
8890
forward_to = [loki.write.local.receiver]
91+
labels = {
92+
service_name = "quickpizza",
93+
service_namespace = "quickpizza",
94+
}
8995
}
9096

9197
loki.write "local" {

docker-compose-cloud.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ services:
99
QUICKPIZZA_OTLP_ENDPOINT: http://alloy:4318
1010
QUICKPIZZA_TRUST_CLIENT_TRACEID: 1
1111
QUICKPIZZA_PYROSCOPE_ENDPOINT: http://alloy:9999
12+
# Set to 1 to use component name as OpenTelemetry service name
13+
# QUICKPIZZA_OTEL_SERVICE_NAME_LEGACY: 1
1214
# must be set with an .env file
1315
QUICKPIZZA_CONF_FARO_URL: "${QUICKPIZZA_CONF_FARO_URL}"
1416
# must be set with an .env file
1517
QUICKPIZZA_CONF_FARO_APP_NAME: "${QUICKPIZZA_CONF_FARO_APP_NAME}"
16-
18+
# OTEL service.instance.id label. Default: local
19+
# QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID: local
1720
# Namespace label in Faro. Default: quickpizza
1821
# QUICKPIZZA_CONF_FARO_APP_NAMESPACE: quickpizza
1922
# Enable logging. Possible values: error, warn, debug. Default: info
2023
# QUICKPIZZA_LOG_LEVEL: debug
21-
# Service name label in Pyroscope. Default: quickpizza
22-
# QUICKPIZZA_PYROSCOPE_NAME: quickpizza
23-
# Namespace label in Pyroscope. Default: quickpizza
24-
# QUICKPIZZA_PYROSCOPE_NAMESPACE: quickpizza
2524

2625
alloy:
2726
image: grafana/alloy:v1.9.1

docker-compose-local.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ services:
1111
QUICKPIZZA_PYROSCOPE_ENDPOINT: http://alloy:9999
1212
# Enable logging. Possible values: error, warn, debug. Default: info
1313
# QUICKPIZZA_LOG_LEVEL: debug
14-
# Service name label in Pyroscope. Default: quickpizza
15-
# QUICKPIZZA_PYROSCOPE_NAME: quickpizza
16-
# Namespace label in Pyroscope. Default: quickpizza
17-
# QUICKPIZZA_PYROSCOPE_NAMESPACE: quickpizza
18-
# Database configuration (default: in-memory SQLite)
19-
# QUICKPIZZA_DB: postgres://user:password@postgres:5432/quickpizza?sslmode=disable
2014

2115
loki:
2216
image: grafana/loki:3.4.3
148 KB
Loading

pkg/http/tracing.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,24 @@ func (t *TraceInstaller) Install(r chi.Router, serviceName string, extraOpts ...
9595
}
9696
}
9797

98+
serviceNamespace, ok := os.LookupEnv("QUICKPIZZA_OTEL_SERVICE_NAMESPACE")
99+
if !ok {
100+
serviceNamespace = "quickpizza"
101+
}
102+
serviceInstanceID, ok := os.LookupEnv("QUICKPIZZA_OTEL_SERVICE_INSTANCE_ID")
103+
if !ok {
104+
serviceInstanceID = "local"
105+
}
106+
98107
// We discard the error here as it cannot possibly take place with the parameters we use.
99108
res, _ := resource.Merge(
100109
resource.Default(),
101110
resource.NewWithAttributes(
102111
semconv.SchemaURL,
103112
semconv.ServiceName(serviceNameAttrValue),
104113
attribute.KeyValue{Key: "service.component", Value: attribute.StringValue(serviceName)},
114+
attribute.KeyValue{Key: "service.namespace", Value: attribute.StringValue(serviceNamespace)},
115+
attribute.KeyValue{Key: "service.instance.id", Value: attribute.StringValue(serviceInstanceID)},
105116
),
106117
)
107118

0 commit comments

Comments
 (0)