Skip to content

Commit 84f4515

Browse files
committed
Avoid automatically adopting tags added to the Core::TagBuilder
For consistency between the different profilers, every tag should be vetted before it gets reported with a profile, as otherwise it's too easy to end up with different tags in different languages.
1 parent dfe568a commit 84f4515

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

lib/datadog/profiling/tag_builder.rb

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,57 @@
11
# frozen_string_literal: true
22

3-
require_relative "../core/tag_builder"
4-
require_relative "../core/utils"
3+
require_relative '../core/tag_builder'
4+
require_relative '../core/utils'
5+
6+
require 'set'
57

68
module Datadog
79
module Profiling
810
# Builds a hash of default plus user tags to be included in a profile
911
#
10-
# When changing or adding profiling-related tags, make sure they are
11-
# kept in sync with
12-
# https://docs.google.com/spreadsheets/d/1LOGMf4c4Avbtn36uZ2SWvhIGKRPLM1BoWkUP4JYj7hA/
13-
# (Datadog internal link).
14-
#
1512
# @api private
1613
module TagBuilder
1714
include Datadog::Profiling::Ext::Transport::HTTP # Tag name constants
1815

16+
# When changing or adding profiling-related tags, make sure they are
17+
# kept in sync with
18+
# https://docs.google.com/spreadsheets/d/1LOGMf4c4Avbtn36uZ2SWvhIGKRPLM1BoWkUP4JYj7hA/
19+
# (Datadog internal link).
20+
#
21+
# For consistency between the different profilers, every tag should be
22+
# vetted before it gets reported with a profile, as otherwise it's too
23+
# easy to end up with different tags in different languages.
24+
ALLOWED_TAGS = Set.new(
25+
[
26+
'env',
27+
'service',
28+
'version',
29+
'git.commit.sha',
30+
'git.repository_url',
31+
'host',
32+
'language',
33+
'runtime',
34+
'runtime_engine',
35+
'runtime_platform',
36+
'runtime_version',
37+
'runtime-id',
38+
'process_id',
39+
'profiler_version',
40+
'profile_seq',
41+
]
42+
).freeze
43+
1944
def self.call(
2045
settings:,
21-
# Other metadata
2246
profile_seq:,
2347
profiler_version: Core::Environment::Identity.gem_datadog_version
2448
)
2549
hash = Core::TagBuilder.tags(settings).merge(
2650
FORM_FIELD_TAG_PROFILER_VERSION => profiler_version,
2751
'profile_seq' => profile_seq.to_s,
2852
)
53+
user_tag_keys = settings.tags.keys
54+
hash.keep_if { |tag| user_tag_keys.include?(tag) || ALLOWED_TAGS.include?(tag) }
2955
Core::Utils.encode_tags(hash)
3056
end
3157
end

spec/datadog/profiling/tag_builder_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
)
2121
end
2222

23+
it "does not include tags that are not allowed" do
24+
expect(Datadog::Core::TagBuilder).to receive(:tags).and_return("not_allowed" => "value")
25+
expect(call).to_not include("not_allowed")
26+
end
27+
2328
describe "unified service tagging" do
2429
[:env, :service, :version].each do |tag|
2530
context "when a #{tag} is defined" do

0 commit comments

Comments
 (0)