Skip to content

Commit b1ba9cc

Browse files
authored
feat: fix default protocol for kyma (#294)
closes #272
1 parent acf7a11 commit b1ba9cc

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
99
### Added
1010

1111
- Skip instrumentation of HANA driver, if it does it itself
12+
- `telemetry-to-otlp`: Automatically switch to `gRPC` (from default `http/protobuf`) when exporting to an endpoint with port `4317`
1213

1314
### Changed
1415

lib/logging/index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ function _getExporter() {
2020

2121
// for kind telemetry-to-otlp based on env vars
2222
if (loggingExporter === 'env') {
23-
const otlp_env = getEnvWithoutDefaults()
24-
const dflt_env = getEnv()
25-
const protocol =
26-
otlp_env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL ??
27-
otlp_env.OTEL_EXPORTER_OTLP_PROTOCOL ??
28-
dflt_env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL ??
29-
dflt_env.OTEL_EXPORTER_OTLP_PROTOCOL
23+
const cstm_env = getEnvWithoutDefaults()
24+
const otlp_env = getEnv()
25+
let protocol = cstm_env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL ?? cstm_env.OTEL_EXPORTER_OTLP_PROTOCOL
26+
// on kyma, the otlp endpoint speaks grpc, but otel's default protocol is http/protobuf -> fix default
27+
if (!protocol) {
28+
const endpoint = otlp_env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT ?? otlp_env.OTEL_EXPORTER_OTLP_ENDPOINT ?? ''
29+
if (endpoint.match(/:4317/)) protocol = 'grpc'
30+
}
31+
protocol ??= otlp_env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL ?? otlp_env.OTEL_EXPORTER_OTLP_PROTOCOL
3032
loggingExporter = { module: _protocol2module[protocol], class: 'OTLPLogExporter' }
3133
}
3234

@@ -100,7 +102,7 @@ module.exports = resource => {
100102

101103
// intercept logs via format
102104
const { format: _format } = cds.log
103-
const format = cds.log.format = function (module, level, ...args) {
105+
const format = (cds.log.format = function (module, level, ...args) {
104106
const res = _format.call(this, module, level, ...args)
105107

106108
let log
@@ -131,7 +133,7 @@ module.exports = resource => {
131133
}
132134

133135
return res
134-
}
136+
})
135137

136138
// replace format function of existing loggers
137139
for (const each in cds.log.loggers) cds.log.loggers[each].setFormat(format)

lib/metrics/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ function _getExporter() {
2929

3030
// for kind telemetry-to-otlp based on env vars
3131
if (metricsExporter === 'env') {
32-
const otlp_env = getEnvWithoutDefaults()
33-
const dflt_env = getEnv()
34-
const protocol =
35-
otlp_env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL ??
36-
otlp_env.OTEL_EXPORTER_OTLP_PROTOCOL ??
37-
dflt_env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL ??
38-
dflt_env.OTEL_EXPORTER_OTLP_PROTOCOL
32+
const cstm_env = getEnvWithoutDefaults()
33+
const otlp_env = getEnv()
34+
let protocol = cstm_env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL ?? cstm_env.OTEL_EXPORTER_OTLP_PROTOCOL
35+
// on kyma, the otlp endpoint speaks grpc, but otel's default protocol is http/protobuf -> fix default
36+
if (!protocol) {
37+
const endpoint = otlp_env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ?? otlp_env.OTEL_EXPORTER_OTLP_ENDPOINT ?? ''
38+
if (endpoint.match(/:4317/)) protocol = 'grpc'
39+
}
40+
protocol ??= otlp_env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL ?? otlp_env.OTEL_EXPORTER_OTLP_PROTOCOL
3941
metricsExporter = { module: _protocol2module[protocol], class: 'OTLPMetricExporter' }
4042
}
4143

lib/tracing/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ function _getExporter() {
8585

8686
// for kind telemetry-to-otlp based on env vars
8787
if (tracingExporter === 'env') {
88-
const otlp_env = getEnvWithoutDefaults()
89-
const dflt_env = getEnv()
90-
const protocol =
91-
otlp_env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL ??
92-
otlp_env.OTEL_EXPORTER_OTLP_PROTOCOL ??
93-
dflt_env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL ??
94-
dflt_env.OTEL_EXPORTER_OTLP_PROTOCOL
88+
const cstm_env = getEnvWithoutDefaults()
89+
const otlp_env = getEnv()
90+
let protocol = cstm_env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL ?? cstm_env.OTEL_EXPORTER_OTLP_PROTOCOL
91+
// on kyma, the otlp endpoint speaks grpc, but otel's default protocol is http/protobuf -> fix default
92+
if (!protocol) {
93+
const endpoint = otlp_env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ?? otlp_env.OTEL_EXPORTER_OTLP_ENDPOINT ?? ''
94+
if (endpoint.match(/:4317/)) protocol = 'grpc'
95+
}
96+
protocol ??= otlp_env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL ?? otlp_env.OTEL_EXPORTER_OTLP_PROTOCOL
9597
tracingExporter = { module: _protocol2module[protocol], class: 'OTLPTraceExporter' }
9698
}
9799

0 commit comments

Comments
 (0)