Skip to content
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
2 changes: 2 additions & 0 deletions source/extensions/tracers/datadog/demo/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ services:
dd-agent:
volumes:
- '/var/run/docker.sock:/var/run/docker.sock:ro'
- '/run/user:/run/user:ro'
- '/proc/:/host/proc/:ro'
- '/sys/fs/cgroup/:/host/sys/fs/cgroup:ro'
environment:
- DOCKER_HOST
- DD_API_KEY
- DD_APM_ENABLED=true
- DD_LOG_LEVEL=ERROR
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/tracers/datadog/demo/envoy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

here=$(dirname "$0")
"$(bazelisk info bazel-genfiles)"/source/exe/envoy-static --config-path "$here"/envoy.yaml "$@"
"$here"/../../../../../bazel-bin/source/exe/envoy-static --config-path "$here"/envoy.yaml "$@"
16 changes: 14 additions & 2 deletions source/extensions/tracers/datadog/span.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,27 @@ void Span::setOperation(absl::string_view operation) {
return;
}

span_->set_name(operation);
// What Envoy calls the operation name more closely corresponds to what
// Datadog calls the resource name.
span_->set_resource_name(operation);
}

void Span::setTag(absl::string_view name, absl::string_view value) {
if (!span_) {
return;
}

span_->set_tag(name, value);
// The special "resource.name" tag is a holdover from when the Datadog tracer
// was OpenTracing-based, and so there was no way to set the Datadog resource
// name directly.
// In Envoy, it's still the case that there's no way to set the Datadog
// resource name directly; so, here if the tag name is "resource.name", we
// actually set the resource name instead of setting a tag.
if (name == "resource.name") {
span_->set_resource_name(value);
} else {
span_->set_tag(name, value);
}
}

void Span::log(SystemTime, const std::string&) {
Expand Down
12 changes: 11 additions & 1 deletion test/extensions/tracers/datadog/span_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,18 @@ TEST_F(DatadogTracerSpanTest, SetOperation) {
ASSERT_NE(nullptr, data_ptr);
const datadog::tracing::SpanData& data = *data_ptr;

EXPECT_EQ("gastric bypass", data.name);
// Setting the operation name actually sets the resource name, because Envoy's
// notion of operation name more closely matches Datadog's notion of resource
// name.
EXPECT_EQ("gastric bypass", data.resource);
}

TEST_F(DatadogTracerSpanTest, SetTag) {
Span span{std::move(span_)};
span.setTag("foo", "bar");
span.setTag("boom", "bam");
span.setTag("foo", "new");
span.setTag("resource.name", "vespene gas");
span.finishSpan();

ASSERT_EQ(1, collector_->chunks.size());
Expand All @@ -152,6 +156,12 @@ TEST_F(DatadogTracerSpanTest, SetTag) {
found = data.tags.find("boom");
ASSERT_NE(data.tags.end(), found);
EXPECT_EQ("bam", found->second);

// The "resource.name" tag is special. It doesn't set a tag, but instead the
// span's resource name.
found = data.tags.find("resource.name");
ASSERT_EQ(data.tags.end(), found);
EXPECT_EQ("vespene gas", data.resource);
}

TEST_F(DatadogTracerSpanTest, InjectContext) {
Expand Down