Skip to content

Commit 1b90aa7

Browse files
authored
Merge pull request #341 from tsloughter/protocol-compression-env
update and add exporter options
2 parents a22fb0e + e16ffd3 commit 1b90aa7

File tree

6 files changed

+104
-24
lines changed

6 files changed

+104
-24
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### [Exporter]
11+
12+
#### Added
13+
14+
- New `opentelemetry_exporter` application environment options:
15+
- `otlp_protocol`: The transport protocol, supported values: `grpc` and `http_protobuf`. Defaults to `http_protobuf`.
16+
- `otlp_traces_protocol`: The transport protocol to use for exporting traces, supported values: `grpc` and `http_protobuf`. Defaults to `http_protobuf`.
17+
- `otlp_compression`: Compression type to use, supported values: `gzip`. Defaults to no compression.
18+
- `otlp_traces_compression`: Compression type to use for exporting traces, supported values: `gzip`. Defaults to no compression.
19+
20+
- New environment variable options:
21+
- `OTEL_EXPORTER_OTLP_PROTOCOL`: The transport protocol to use, supported values: `grpc` and `http_protobuf`. Defaults to `http_protobuf`
22+
- `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL`: The transport protocol to use for exporting traces, supported values: `grpc` and `http_protobuf`. Defaults to `http_protobuf`.
23+
- `OTEL_EXPORTER_OTLP_COMPRESSION`: Compression to use, supported value: gzip. Defaults to no compression.
24+
- `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION`: Compression to use when exporting traces, supported value: gzip. Defaults to no compression.
25+
1026
## [API 1.0.0-rc.4.1] - 2021-12-28
1127

1228
##### Fixed

apps/opentelemetry_exporter/README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,27 @@ config :opentelemetry, :processors,
5151
- `otlp_endpoint`: The URL to send traces and metrics to, for traces the path `v1/traces` is appended to the path in the URL.
5252
- `otlp_traces_endpoint`: URL to send only traces to. This takes precedence for exporting traces and the path of the URL is kept as is, no suffix is appended.
5353
- `otlp_headers`: List of additional headers (`[{unicode:chardata(), unicode:chardata()}]`) to add to export requests.
54-
- `otlp_traces_headers`: Additional headers (`[{unicode:chardata(), unicode:chardata()}]`) to add to only trace export requests.
55-
54+
- `otlp_traces_headers`: Additional headers (`[{unicode:chardata(),
55+
unicode:chardata()}]`) to add to only trace export requests.
56+
- `otlp_protocol`: The transport protocol, supported values: `grpc` and `http_protobuf`. Defaults to `http_protobuf`.
57+
- `otlp_traces_protocol`: The transport protocol to use for exporting traces, supported values: `grpc` and `http_protobuf`. Defaults to `http_protobuf`.
58+
- `otlp_compression`: Compression type to use, supported values: `gzip`. Defaults to no compression.
59+
- `otlp_traces_compression`: Compression type to use for exporting traces, supported values: `gzip`. Defaults to no compression.
5660

5761
``` erlang
5862
{opentelemetry_exporter,
59-
[{otlp_endpoint, "https://api.honeycomb.io:443"},
63+
[{otlp_protocol, grpc},
64+
{otlp_compression, gzip},
65+
{otlp_endpoint, "https://api.honeycomb.io:443"},
6066
{otlp_headers, [{"x-honeycomb-dataset", "experiments"}]}]}
6167
```
6268

6369
An Elixir release uses `releases.exs`:
6470

6571
``` elixir
6672
config :opentelemetry_exporter,
73+
otlp_protocol: :grpc,
74+
otlp_compression: :gzip,
6775
otlp_endpoint: "https://api.honeycomb.io:443",
6876
otlp_headers: [{"x-honeycomb-dataset", "experiments"}]
6977
```
@@ -87,11 +95,16 @@ for more information on securing HTTP requests in Erlang.
8795
- `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`: URL to send only traces to. This takes precedence for exporting traces and the path of the URL is kept as is, no suffix is appended.
8896
- `OTEL_EXPORTER_OTLP_HEADERS`: List of additional headers to add to export requests.
8997
- `OTEL_EXPORTER_OTLP_TRACES_HEADERS`: Additional headers to add to only trace export requests.
98+
- `OTEL_EXPORTER_OTLP_PROTOCOL`: The transport protocol to use, supported values: `grpc` and `http_protobuf`. Defaults to `http_protobuf`
99+
- `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL`: The transport protocol to use for exporting traces, supported values: `grpc` and `http_protobuf`. Defaults to `http_protobuf`.
100+
- `OTEL_EXPORTER_OTLP_COMPRESSION`: Compression to use, supported value: gzip. Defaults to no compression.
101+
- `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION`: Compression to use when exporting traces, supported value: gzip. Defaults to no compression.
90102

91103
Example usage of setting the environment variables:
92104
```
93105
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://api.honeycomb.io:443
94-
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
106+
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=grpc
107+
OTEL_EXPORTER_OTLP_TRACES_COMPRESSION=gzip
95108
OTEL_EXPORTER_OTLP_TRACES_HEADERS=x-honeycomb-team=<HONEYCOMB API TOKEN>,x-honeycomb-dataset=experiments
96109
```
97110

apps/opentelemetry_exporter/src/opentelemetry_exporter.erl

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,29 @@
2424
%% `otlp_endpoint': The URL to send traces and metrics to, for traces the
2525
%% path `v1/traces' is appended to the path in the URL.
2626
%% </li>
27-
%% <li>`otlp_traces_endpoint': URL to send only traces to. This takes precedence
27+
%% <li>
28+
%% `otlp_traces_endpoint': URL to send only traces to. This takes precedence
2829
%% for exporting traces and the path of the URL is kept as is, no suffix is
2930
%% appended.
3031
%% </li>
31-
%% <li>`otlp_headers': List of additional headers (`[{unicode:chardata(), unicode:chardata()}]') to add to export requests.</li>
32+
%% <li>
33+
%% `otlp_headers': List of additional headers (`[{unicode:chardata(), unicode:chardata()}]') to add to export requests.
34+
%% </li>
3235
%% <li>
3336
%% `otlp_traces_headers': Additional headers (`[{unicode:chardata(), unicode:chardata()}]') to add to only trace export requests.
3437
%% </li>
38+
%% <li>
39+
%% `otlp_protocol': The transport protocol, supported values: `grpc' and `http_protobuf'. Defaults to `http_protobuf'.
40+
%% </li>
41+
%% <li>
42+
%% `otlp_traces_protocol': The transport protocol to use for exporting traces, supported values: `grpc' and `http_protobuf'. Defaults to `http_protobuf'
43+
%% </li>
44+
%% <li>
45+
%% `otlp_compression': Compression type to use, supported values: `gzip'. Defaults to no compression.
46+
%% </li>
47+
%% <li>
48+
%% `otlp_traces_compression': Compression type to use for exporting traces, supported values: `gzip'. Defaults to no compression.
49+
%% </li>
3550
%% </ul>
3651
%%
3752
%% There also corresponding OS environment variables can also set those
@@ -42,6 +57,10 @@
4257
%% <li>`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT': URL to send only traces to. This takes precedence for exporting traces and the path of the URL is kept as is, no suffix is appended.</li>
4358
%% <li>`OTEL_EXPORTER_OTLP_HEADERS': List of additional headers to add to export requests.</li>
4459
%% <li>`OTEL_EXPORTER_OTLP_TRACES_HEADERS': Additional headers to add to only trace export requests.</li>
60+
%% <li>`OTEL_EXPORTER_OTLP_PROTOCOL': The transport protocol to use, supported values: `grpc' and `http_protobuf'. Defaults to `http_protobuf'.</li>
61+
%% <li>`OTEL_EXPORTER_OTLP_TRACES_PROTOCOL': The transport protocol to use for exporting traces, supported values: `grpc' and `http_protobuf'. Defaults to `http_protobuf'.</li>
62+
%% <li>`OTEL_EXPORTER_OTLP_COMPRESSION': Compression to use, supported value: gzip. Defaults to no compression./li>
63+
%% <li>`OTEL_EXPORTER_OTLP_TRACES_COMPRESSION': Compression to use when exporting traces, supported value: gzip. Defaults to no compression.</li>
4564
%% </ul>
4665
%%
4766
%% @end
@@ -74,9 +93,9 @@
7493

7594
-define(DEFAULT_ENDPOINTS, [#{host => "localhost",
7695
path => [],
77-
port => 4317,
78-
scheme => "https"}]).
79-
-define(DEFAULT_PORT, 4317).
96+
port => 4318,
97+
scheme => "http"}]).
98+
-define(DEFAULT_PORT, 4318).
8099
-define(DEFAULT_TRACES_PATH, "v1/traces").
81100

82101
-type headers() :: [{unicode:chardata(), unicode:chardata()}].
@@ -310,7 +329,11 @@ merge_with_environment(Opts) ->
310329
Config = #{otlp_endpoint => undefined,
311330
otlp_traces_endpoint => undefined,
312331
otlp_headers => undefined,
313-
otlp_traces_headers => undefined},
332+
otlp_traces_headers => undefined,
333+
otlp_protocol => undefined,
334+
otlp_traces_protocol => undefined,
335+
otlp_compression => undefined,
336+
otlp_traces_compression => undefined},
314337

315338
AppEnv = application:get_all_env(opentelemetry_exporter),
316339
AppOpts = otel_configuration:merge_list_with_environment(config_mapping(), AppEnv, Config),
@@ -320,7 +343,13 @@ merge_with_environment(Opts) ->
320343
Opts2 = update_opts(otlp_traces_endpoint, endpoints, ?DEFAULT_ENDPOINTS, AppOpts, Opts1, fun maybe_to_list/1),
321344

322345
Opts3 = update_opts(otlp_headers, headers, [], AppOpts, Opts2),
323-
update_opts(otlp_traces_headers, headers, [], AppOpts, Opts3).
346+
Opts4 = update_opts(otlp_traces_headers, headers, [], AppOpts, Opts3),
347+
348+
Opts5 = update_opts(otlp_protocol, protocol, http_protobuf, AppOpts, Opts4),
349+
Opts6 = update_opts(otlp_traces_protocol, protocol, http_protobuf, AppOpts, Opts5),
350+
351+
Opts7 = update_opts(otlp_compression, compression, undefined, AppOpts, Opts6),
352+
update_opts(otlp_traces_compression, compression, undefined, AppOpts, Opts7).
324353

325354
maybe_to_list(E) when is_list(E) ->
326355
case io_lib:printable_list(E) of
@@ -376,13 +405,24 @@ config_mapping() ->
376405

377406
%% headers to include in requests the exporter makes over the Otel protocol
378407
{"OTEL_EXPORTER_OTLP_HEADERS", otlp_headers, key_value_list},
379-
{"OTEL_EXPORTER_OTLP_TRACES_HEADERS", otlp_traces_headers, key_value_list}
408+
{"OTEL_EXPORTER_OTLP_TRACES_HEADERS", otlp_traces_headers, key_value_list},
380409
%% {"OTEL_EXPORTER_OTLP_METRICS_HEADERS", otlp_metrics_headers, "", key_value_list}
381410

382-
%% the following are not yet defined in the spec
383-
%% {"OTEL_EXPORTER_OTLP_PROTOCOL", exporter_otlp_protocol, "", string},
384-
%% {"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", exporter_otlp_traces_protocol, "", string},
385-
%% {"OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", exporter_otlp_metrics_protocol, "", string}
411+
{"OTEL_EXPORTER_OTLP_PROTOCOL", otlp_protocol, existing_atom},
412+
{"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", otlp_traces_protocol, existing_atom},
413+
%% {"OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", exporter_otlp_metrics_protocol, string}
414+
415+
{"OTEL_EXPORTER_OTLP_COMPRESSION", otlp_compression, existing_atom},
416+
{"OTEL_EXPORTER_OTLP_TRACES_COMPRESSION", otlp_traces_compression, existing_atom}
417+
%% {"OTEL_EXPORTER_OTLP_METRICS_COMPRESSION", otlp_metrics_compression, existing_atom}
418+
419+
%% {"OTEL_EXPORTER_OTLP_CERTIFICATE", otlp_certificate, path},
420+
%% {"OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE", otlp_traces_certificate, path},
421+
%% {"OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE", otlp_metrics_certificate, path},
422+
423+
%% {"OTEL_EXPORTER_OTLP_TIMEOUT", otlp_timeout, integer},
424+
%% {"OTEL_EXPORTER_OTLP_TRACES_TIMEOUT", otlp_traces_timeout, integer},
425+
%% {"OTEL_EXPORTER_OTLP_METRICS_TIMEOUT", otlp_metrics_timeout, integer}
386426
].
387427

388428
tab_to_proto(Tab, Resource) ->

apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ configuration(_Config) ->
7777
?assertMatch([#{scheme := "https", host := "localhost", port := 443, path := "/used/path"}],
7878
opentelemetry_exporter:endpoints(<<"https://localhost:443/used/path">>, [])),
7979

80-
?assertMatch([#{scheme := "http", host := "localhost", port := 4317, path := []}],
80+
?assertMatch([#{scheme := "http", host := "localhost", port := 4318, path := []}],
8181
opentelemetry_exporter:endpoints("http://localhost", [])),
8282

8383
?assertMatch([], opentelemetry_exporter:endpoints("://badendpoint", [])),
@@ -97,15 +97,19 @@ configuration(_Config) ->
9797
?assertEqual(#{endpoints =>
9898
[#{host => "localhost", path => "/v1/traces", port => 4343,
9999
scheme => "http"}],
100-
headers => [{"key1", "value1"}]},
100+
headers => [{"key1", "value1"}],
101+
compression => undefined,
102+
protocol => http_protobuf},
101103
opentelemetry_exporter:merge_with_environment(#{endpoints => []})),
102104

103105
os:putenv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://localhost:4343/internal"),
104106
os:putenv("OTEL_EXPORTER_OTLP_HEADERS", "key1=value1"),
105107
?assertEqual(#{endpoints =>
106108
[#{host => "localhost", path => "/internal/v1/traces", port => 4343,
107109
scheme => "http"}],
108-
headers => [{"key1", "value1"}]},
110+
headers => [{"key1", "value1"}],
111+
compression => undefined,
112+
protocol => http_protobuf},
109113
opentelemetry_exporter:merge_with_environment(#{endpoints => []})),
110114

111115
%% TRACES_ENDPOINT takes precedence
@@ -114,16 +118,22 @@ configuration(_Config) ->
114118
?assertEqual(#{endpoints =>
115119
[#{host => "localhost", path => "/traces/path", port => 5353,
116120
scheme => "http"}],
117-
headers => [{"key2", "value2"}]},
121+
headers => [{"key2", "value2"}],
122+
compression => undefined,
123+
protocol => http_protobuf},
118124
opentelemetry_exporter:merge_with_environment(#{endpoints => []})),
119125

126+
os:putenv("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc"),
127+
?assertMatch(#{protocol := grpc},
128+
opentelemetry_exporter:merge_with_environment(#{})),
120129

121130
ok
122131
after
123132
os:unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT"),
124133
os:unsetenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"),
125134
os:unsetenv("OTEL_EXPORTER_OTLP_HEADERS"),
126-
os:unsetenv("OTEL_EXPORTER_OTLP_TRACES_HEADERS")
135+
os:unsetenv("OTEL_EXPORTER_OTLP_TRACES_HEADERS"),
136+
os:unsetenv("OTEL_EXPORTER_OTLP_PROTOCOL")
127137
end.
128138

129139
ets_instrumentation_info(_Config) ->
@@ -228,11 +238,12 @@ verify_export(Config) ->
228238
os:putenv("OTEL_RESOURCE_ATTRIBUTES", "service.name=my-test-service,service.version=98da75ea6d38724743bf42b45565049238d86b3f"),
229239
Protocol = ?config(protocol, Config),
230240
Compression = ?config(compression, Config),
241+
231242
Port = case Protocol of
232243
grpc ->
233244
4317;
234245
http_protobuf ->
235-
55681
246+
4318
236247
end,
237248
{ok, State} = opentelemetry_exporter:init(#{protocol => Protocol,
238249
compression => Compression,

config/otel-collector-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ receivers:
55
grpc:
66
endpoint: "0.0.0.0:4317"
77
http:
8-
endpoint: "0.0.0.0:55681"
8+
endpoint: "0.0.0.0:4318"
99
processors:
1010
batch:
1111
send_batch_size: 1024

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ services:
55
command: ["--config=/conf/otel-collector-config.yaml"]
66
privileged: true
77
ports:
8-
- 55681:55681
98
- 4317:4317
9+
- 4318:4318
1010
volumes:
1111
- ./config/otel-collector-config.yaml:/conf/otel-collector-config.yaml
1212
links:

0 commit comments

Comments
 (0)