Skip to content

Commit

Permalink
Add binary mode for otlp_http_exporter
Browse files Browse the repository at this point in the history
Signed-off-by: owent <[email protected]>
  • Loading branch information
owent committed Jun 5, 2021
1 parent 69e4f24 commit 6953eb3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
6 changes: 3 additions & 3 deletions examples/otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ OpenTelemetry Collector with an OTLP receiver by running:
- On Unix based systems use:

```console
docker run --rm -it -p 4317:4317 -v $(pwd)/examples/otlp:/cfg otel/opentelemetry-collector:0.19.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml
docker run --rm -it -p 4317:4317 -p 55681:55681 -v $(pwd)/examples/otlp:/cfg otel/opentelemetry-collector:0.19.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml
```

- On Windows use:

```console
docker run --rm -it -p 4317:4317 -v "%cd%/examples/otlp":/cfg otel/opentelemetry-collector:0.19.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml
docker run --rm -it -p 4317:4317 -p 55681:55681 -v "%cd%/examples/otlp":/cfg otel/opentelemetry-collector:0.19.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml
```

Note that the OTLP exporter connects to the Collector at `localhost:4317` by
default. This can be changed with first argument from command-line, for example:
`./example_otlp_grpc gateway.docker.internal:4317` and
`./example_otlp_http gateway.docker.internal:4317`.
`./example_otlp_http gateway.docker.internal:55681/v1/traces`.

Once you have the Collector running, see
[CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and
Expand Down
14 changes: 13 additions & 1 deletion examples/otlp/http_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "opentelemetry/sdk/trace/tracer_provider.h"
#include "opentelemetry/trace/provider.h"

#include <string>

#include "foo_library/foo_library.h"

namespace trace = opentelemetry::trace;
Expand Down Expand Up @@ -36,7 +38,17 @@ int main(int argc, char *argv[])
opts.url = argv[1];
if (argc > 2)
{
opts.console_debug = false;
std::string debug = argv[2];
opts.console_debug = debug != "" && debug != "0" && debug != "no";
}

if (argc > 3)
{
std::string binary_mode = argv[3];
if (binary_mode.size() >= 3 && binary_mode.substr(0, 3) == "bin")
{
opts.content_type = opentelemetry::exporter::otlp::HttpRequestContentType::kBinary;
}
}
}
// Removing this line will leave the default noop TracerProvider in place.
Expand Down
4 changes: 4 additions & 0 deletions examples/otlp/opentelemetry-collector-config/config.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ receivers:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: "0.0.0.0:55681"
cors_allowed_origins:
- '*'
service:
pipelines:
traces:
Expand Down
23 changes: 15 additions & 8 deletions exporters/otlp/test/otlp_http_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,13 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTest)
resource_attributes["vec_string_value"] = std::vector<std::string>{"vector", "string"};
auto resource = opentelemetry::sdk::resource::Resource::Create(resource_attributes);

auto processor = std::unique_ptr<sdk::trace::SpanProcessor>(new sdk::trace::BatchSpanProcessor(
std::move(exporter),
sdk::trace::BatchSpanProcessorOptions{5, std::chrono::milliseconds(256), 5}));
auto provider = nostd::shared_ptr<trace::TracerProvider>(
auto processor_opts = sdk::trace::BatchSpanProcessorOptions();
processor_opts.max_export_batch_size = 5;
processor_opts.max_queue_size = 5;
processor_opts.schedule_delay_millis = std::chrono::milliseconds(256);
auto processor = std::unique_ptr<sdk::trace::SpanProcessor>(
new sdk::trace::BatchSpanProcessor(std::move(exporter), processor_opts));
auto provider = nostd::shared_ptr<trace::TracerProvider>(
new sdk::trace::TracerProvider(std::move(processor), resource));

std::string report_trace_id;
Expand Down Expand Up @@ -250,10 +253,14 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTest)
resource_attributes["vec_string_value"] = std::vector<std::string>{"vector", "string"};
auto resource = opentelemetry::sdk::resource::Resource::Create(resource_attributes);

auto processor = std::unique_ptr<sdk::trace::SpanProcessor>(new sdk::trace::BatchSpanProcessor(
std::move(exporter),
sdk::trace::BatchSpanProcessorOptions{5, std::chrono::milliseconds(256), 5}));
auto provider = nostd::shared_ptr<trace::TracerProvider>(
auto processor_opts = sdk::trace::BatchSpanProcessorOptions();
processor_opts.max_export_batch_size = 5;
processor_opts.max_queue_size = 5;
processor_opts.schedule_delay_millis = std::chrono::milliseconds(256);

auto processor = std::unique_ptr<sdk::trace::SpanProcessor>(
new sdk::trace::BatchSpanProcessor(std::move(exporter), processor_opts));
auto provider = nostd::shared_ptr<trace::TracerProvider>(
new sdk::trace::TracerProvider(std::move(processor), resource));

std::string report_trace_id;
Expand Down

0 comments on commit 6953eb3

Please sign in to comment.