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

Fix metric delivery #330

Merged
merged 3 commits into from
Jun 3, 2022
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
4 changes: 4 additions & 0 deletions K8s/charts/otel-shop/templates/cart-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ spec:
fieldPath: status.hostIP
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ .Values.opentelemetry.exporter.otlp.endpoint }}
{{- if ne .Values.opentelemetry.exporter.otlp.headers "" }}
- name: OTEL_EXPORTER_OTLP_HEADERS
value: {{ .Values.opentelemetry.exporter.otlp.headers }}
{{- end }}
- name: OTEL_SERVICE_NAME
value: {{ .Release.Name }}-catalogue
- name: REDIS_URL
Expand Down
4 changes: 4 additions & 0 deletions K8s/charts/otel-shop/templates/catalogue-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ spec:
fieldPath: status.hostIP
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ .Values.opentelemetry.exporter.otlp.endpoint }}
{{- if ne .Values.opentelemetry.exporter.otlp.headers "" }}
- name: OTEL_EXPORTER_OTLP_HEADERS
value: {{ .Values.opentelemetry.exporter.otlp.headers }}
{{- end }}
- name: OTEL_SERVICE_NAME
value: {{ .Release.Name }}-catalogue
- name: MONGO_URL
Expand Down
4 changes: 4 additions & 0 deletions K8s/charts/otel-shop/templates/dispatch-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ spec:
fieldPath: status.hostIP
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ .Values.opentelemetry.exporter.otlp.endpoint }}
{{- if ne .Values.opentelemetry.exporter.otlp.headers "" }}
- name: OTEL_EXPORTER_OTLP_HEADERS
value: {{ .Values.opentelemetry.exporter.otlp.headers }}
{{- end }}
- name: OTEL_SERVICE_NAME
value: {{ .Release.Name }}-dispatch
resources:
Expand Down
4 changes: 4 additions & 0 deletions K8s/charts/otel-shop/templates/front-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ spec:
fieldPath: status.hostIP
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ .Values.opentelemetry.exporter.otlp.endpoint }}
{{- if ne .Values.opentelemetry.exporter.otlp.headers "" }}
- name: OTEL_EXPORTER_OTLP_HEADERS
value: {{ .Values.opentelemetry.exporter.otlp.headers }}
{{- end }}
- name: OTEL_SERVICE_NAME
value: {{ .Release.Name }}-front
ports:
Expand Down
4 changes: 4 additions & 0 deletions K8s/charts/otel-shop/templates/payment-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ spec:
fieldPath: status.hostIP
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://{{ .Values.opentelemetry.exporter.otlp.endpoint }}
{{- if ne .Values.opentelemetry.exporter.otlp.headers "" }}
- name: OTEL_EXPORTER_OTLP_HEADERS
value: {{ .Values.opentelemetry.exporter.otlp.headers }}
{{- end }}
- name: OTEL_SERVICE_NAME
value: {{ .Release.Name }}-payment
{{- if .Values.payment.gateway }}
Expand Down
4 changes: 4 additions & 0 deletions K8s/charts/otel-shop/templates/ratings-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ spec:
fieldPath: status.hostIP
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ .Values.opentelemetry.exporter.otlp.endpoint }}
{{- if ne .Values.opentelemetry.exporter.otlp.headers "" }}
- name: OTEL_EXPORTER_OTLP_HEADERS
value: {{ .Values.opentelemetry.exporter.otlp.headers }}
{{- end }}
- name: OTEL_SERVICE_NAME
value: {{ .Release.Name }}-ratings
ports:
Expand Down
4 changes: 4 additions & 0 deletions K8s/charts/otel-shop/templates/shipping-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ spec:
fieldPath: status.hostIP
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://{{ .Values.opentelemetry.exporter.otlp.endpoint }}
{{- if ne .Values.opentelemetry.exporter.otlp.headers "" }}
- name: OTEL_EXPORTER_OTLP_HEADERS
value: {{ .Values.opentelemetry.exporter.otlp.headers }}
{{- end }}
- name: OTEL_SERVICE_NAME
value: {{ .Release.Name }}-shipping
- name: OTEL_TRACES_SAMPLER
Expand Down
4 changes: 4 additions & 0 deletions K8s/charts/otel-shop/templates/user-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ spec:
fieldPath: status.hostIP
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ .Values.opentelemetry.exporter.otlp.endpoint }}
{{- if ne .Values.opentelemetry.exporter.otlp.headers "" }}
- name: OTEL_EXPORTER_OTLP_HEADERS
value: {{ .Values.opentelemetry.exporter.otlp.headers }}
{{- end }}
- name: OTEL_SERVICE_NAME
value: {{ .Release.Name }}-user
- name: MONGO_URL
Expand Down
4 changes: 4 additions & 0 deletions K8s/charts/otel-shop/templates/web-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ spec:
fieldPath: status.hostIP
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ .Values.opentelemetry.exporter.otlp.endpoint }}
{{- if ne .Values.opentelemetry.exporter.otlp.headers "" }}
- name: OTEL_EXPORTER_OTLP_HEADERS
value: {{ .Values.opentelemetry.exporter.otlp.headers }}
{{- end }}
- name: OTEL_SERVICE_NAME
value: {{ .Release.Name }}-web
{{- if .Values.eum.key }}
Expand Down
1 change: 1 addition & 0 deletions K8s/charts/otel-shop/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ opentelemetry:
exporter:
otlp:
endpoint: "$(INSTANA_AGENT_HOST):4317"
headers: ""
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ helm upgrade otel-shop otel-shop \
--repo https://instana.github.io/otel-shop/
```

### Sending OTLP somewhere else

This chart can as well as adressing Instana, send the data to some other destination, via OTLP.

The following settings can be used:

`opentelemetry.exporter.otlp.endpoint` - Set the OTLP endpoint to send the data to (defaulting to Instana Agent)
`opentelemetry.exporter.otlp.headers` - Set a list of comma-separated headers for the OTLP exporter (defaulting to blanks)

## License

Apache 2.0
12 changes: 8 additions & 4 deletions cart/monitoring.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
'use strict';

const { MeterProvider, ConsoleMetricExporter } = require('@opentelemetry/sdk-metrics-base');
const { MeterProvider, PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics-base');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-grpc');

const otlpExporter = new OTLPMetricExporter({
url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT
});

const meter = new MeterProvider({
const meterProvider = new MeterProvider({});

meterProvider.addMetricReader(new PeriodicExportingMetricReader({
exporter: otlpExporter,
interval: 1000,
}).getMeter('your-meter-name');
exportIntervalMillis: 1000,
}));

const meter = meterProvider.getMeter('cart-meter');

const requestCount = meter.createCounter("requests", {
description: "Count all incoming requests"
Expand Down
12 changes: 8 additions & 4 deletions catalogue/monitoring.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
'use strict';

const { MeterProvider, ConsoleMetricExporter } = require('@opentelemetry/sdk-metrics-base');
const { MeterProvider, PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics-base');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-grpc');

const otlpExporter = new OTLPMetricExporter({
url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT
});

const meter = new MeterProvider({
const meterProvider = new MeterProvider({});

meterProvider.addMetricReader(new PeriodicExportingMetricReader({
exporter: otlpExporter,
interval: 1000,
}).getMeter('your-meter-name');
exportIntervalMillis: 1000,
}));

const meter = meterProvider.getMeter('catalogue-meter');

const requestCount = meter.createCounter("requests", {
description: "Count all incoming requests"
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ services:
app-network:
environment:
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:?No OpenTelemetry collector specified via OTEL_EXPORTER_OTLP_ENDPOINT}
OTEL_EXPORTER_OTLP_HEADERS: ${OTEL_EXPORTER_OTLP_HEADERS:?No OpenTelemetry headers specified via OTEL_EXPORTER_OTLP_HEADERS}
OTEL_SERVICE_NAME: otel-shop-dispatch
logging:
<<: *logging
Expand All @@ -74,6 +75,7 @@ services:
RATINGS_HOST: ratings
USER_HOST: user
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:?No OpenTelemetry collector specified via OTEL_EXPORTER_OTLP_ENDPOINT}
OTEL_EXPORTER_OTLP_HEADERS: ${OTEL_EXPORTER_OTLP_HEADERS:?No OpenTelemetry headers specified via OTEL_EXPORTER_OTLP_HEADERS}
OTEL_SERVICE_NAME: otel-shop-front
volumes:
- ./front/conf/otel-nginx.toml:/conf/otel-nginx.toml
Expand Down Expand Up @@ -105,6 +107,7 @@ services:
context: web
environment:
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:?No OpenTelemetry collector specified via OTEL_EXPORTER_OTLP_ENDPOINT}
OTEL_EXPORTER_OTLP_HEADERS: ${OTEL_EXPORTER_OTLP_HEADERS:?No OpenTelemetry headers specified via OTEL_EXPORTER_OTLP_HEADERS}
OTEL_SERVICE_NAME: otel-shop-web
volumes:
- ./web/conf/opentelemetry.conf:/etc/apache2/mods-available/opentelemetry.conf
Expand Down Expand Up @@ -137,6 +140,7 @@ services:
app-network:
environment:
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:?No OpenTelemetry collector specified via OTEL_EXPORTER_OTLP_ENDPOINT}
OTEL_EXPORTER_OTLP_HEADERS: ${OTEL_EXPORTER_OTLP_HEADERS:?No OpenTelemetry headers specified via OTEL_EXPORTER_OTLP_HEADERS}
OTEL_SERVICE_NAME: otel-shop-cart
healthcheck:
test:
Expand Down Expand Up @@ -164,6 +168,7 @@ services:
app-network:
environment:
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:?No OpenTelemetry collector specified via OTEL_EXPORTER_OTLP_ENDPOINT}
OTEL_EXPORTER_OTLP_HEADERS: ${OTEL_EXPORTER_OTLP_HEADERS:?No OpenTelemetry headers specified via OTEL_EXPORTER_OTLP_HEADERS}
OTEL_SERVICE_NAME: otel-shop-catalogue
healthcheck:
test:
Expand Down Expand Up @@ -194,6 +199,7 @@ services:
REDIS_URL: redis://redis:6379
MONGO_URL: mongodb://mongodb:27017/users
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:?No OpenTelemetry collector specified via OTEL_EXPORTER_OTLP_ENDPOINT}
OTEL_EXPORTER_OTLP_HEADERS: ${OTEL_EXPORTER_OTLP_HEADERS:?No OpenTelemetry headers specified via OTEL_EXPORTER_OTLP_HEADERS}
OTEL_SERVICE_NAME: otel-shop-user
healthcheck:
test:
Expand All @@ -220,6 +226,7 @@ services:
CATALOGUE_URL: http://catalogue:8080
PDO_URL: mysql:host=mysql;dbname=ratings;charset=utf8mb4
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:?No OpenTelemetry collector specified via OTEL_EXPORTER_OTLP_ENDPOINT}
OTEL_EXPORTER_OTLP_HEADERS: ${OTEL_EXPORTER_OTLP_HEADERS:?No OpenTelemetry headers specified via OTEL_EXPORTER_OTLP_HEADERS}
OTEL_PROPAGATORS: w3c
OTEL_EXPORTER_OTLP_PROTOCOL: grpc
OTEL_SERVICE_NAME: otel-shop-ratings
Expand Down Expand Up @@ -254,6 +261,7 @@ services:
app-network:
environment:
OTEL_EXPORTER_OTLP_ENDPOINT: http://${OTEL_EXPORTER_OTLP_ENDPOINT:?No OpenTelemetry collector specified via OTEL_EXPORTER_OTLP_ENDPOINT}
OTEL_EXPORTER_OTLP_HEADERS: ${OTEL_EXPORTER_OTLP_HEADERS:?No OpenTelemetry headers specified via OTEL_EXPORTER_OTLP_HEADERS}
OTEL_SERVICE_NAME: otel-shop-payment
OTEL_TRACES_EXPORTER: otlp_proto_grpc
OTEL_RESOURCE_ATTRIBUTES: service.name=otel-shop-payment
Expand Down Expand Up @@ -290,6 +298,7 @@ services:
DB_HOST: mysql
REDIS_URL: redis://redis:6379
OTEL_EXPORTER_OTLP_ENDPOINT: http://${OTEL_EXPORTER_OTLP_ENDPOINT:?No OpenTelemetry collector specified via OTEL_EXPORTER_OTLP_ENDPOINT}
OTEL_EXPORTER_OTLP_HEADERS: ${OTEL_EXPORTER_OTLP_HEADERS:?No OpenTelemetry headers specified via OTEL_EXPORTER_OTLP_HEADERS}
OTEL_SERVICE_NAME: otel-shop-shipping
OTEL_TRACES_SAMPLER: always_on
healthcheck:
Expand Down
3 changes: 3 additions & 0 deletions env.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ INSTANA_OTLP_ENDPOINT=your-otlp-endpoint.here:4317
# For use with otel-collector, set this to "otel-collector:4317"
OTEL_EXPORTER_OTLP_ENDPOINT=collector:4317

# In case you need to supply additional headers
OTEL_EXPORTER_OTLP_HEADERS=x-instana-key=${agent_key},x-instana-time=0

# [bump]
PROJECT_VERSION=0.1.160
REPOSITORY=instanacedricziel/otel-shop
3 changes: 3 additions & 0 deletions ratings/html/var/cache/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!.gitkeep
!.gitignore
*
12 changes: 8 additions & 4 deletions user/monitoring.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
'use strict';

const { MeterProvider, ConsoleMetricExporter } = require('@opentelemetry/sdk-metrics-base');
const { MeterProvider, PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics-base');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-grpc');

const otlpExporter = new OTLPMetricExporter({
url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT
});

const meter = new MeterProvider({
const meterProvider = new MeterProvider({});

meterProvider.addMetricReader(new PeriodicExportingMetricReader({
exporter: otlpExporter,
interval: 1000,
}).getMeter('your-meter-name');
exportIntervalMillis: 1000,
}));

const meter = meterProvider.getMeter('user-meter');

const requestCount = meter.createCounter("requests", {
description: "Count all incoming requests"
Expand Down