Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit ae131d5

Browse files
authored
Add X-Cloud-Trace-Context: helpers. (#257)
* Add FromCloudTraceContextHeader(). * Also add a matching ToCloudTraceContextHeader(). * Split out :span_context into its own build target. * Add tests. * Add a benchmark.
1 parent 5fc3560 commit ae131d5

File tree

7 files changed

+424
-21
lines changed

7 files changed

+424
-21
lines changed

opencensus/context/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ cc_test(
5454
"//opencensus/tags:with_tag_map",
5555
"//opencensus/trace",
5656
"//opencensus/trace:context_util",
57+
"//opencensus/trace:span_context",
5758
"//opencensus/trace:with_span",
5859
"@com_google_googletest//:gtest_main",
5960
],

opencensus/trace/BUILD

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,13 @@ cc_library(
3737
"internal/running_span_store_impl.cc",
3838
"internal/sampler.cc",
3939
"internal/span.cc",
40-
"internal/span_context.cc",
4140
"internal/span_data.cc",
4241
"internal/span_exporter.cc",
4342
"internal/span_exporter_impl.cc",
44-
"internal/span_id.cc",
4543
"internal/span_impl.cc",
4644
"internal/status.cc",
4745
"internal/trace_config.cc",
4846
"internal/trace_config_impl.cc",
49-
"internal/trace_id.cc",
50-
"internal/trace_options.cc",
5147
],
5248
hdrs = [
5349
"attribute_value_ref.h",
@@ -70,17 +66,15 @@ cc_library(
7066
"internal/trace_params_impl.h",
7167
"sampler.h",
7268
"span.h",
73-
"span_context.h",
74-
"span_id.h",
7569
"status_code.h",
7670
"trace_config.h",
77-
"trace_id.h",
78-
"trace_options.h",
7971
"trace_params.h",
8072
],
8173
copts = DEFAULT_COPTS,
8274
visibility = ["//visibility:public"],
8375
deps = [
76+
":cloud_trace_context",
77+
":span_context",
8478
"//opencensus/common/internal:random_lib",
8579
"@com_google_absl//absl/base:core_headers",
8680
"@com_google_absl//absl/base:endian",
@@ -91,6 +85,23 @@ cc_library(
9185
],
9286
)
9387

88+
cc_library(
89+
name = "cloud_trace_context",
90+
srcs = [
91+
"internal/cloud_trace_context.cc",
92+
],
93+
hdrs = [
94+
"propagation/cloud_trace_context.h",
95+
],
96+
copts = DEFAULT_COPTS,
97+
visibility = ["//visibility:public"],
98+
deps = [
99+
":span_context",
100+
"@com_google_absl//absl/base:endian",
101+
"@com_google_absl//absl/strings",
102+
],
103+
)
104+
94105
cc_library(
95106
name = "context_util",
96107
srcs = ["internal/context_util.cc"],
@@ -103,6 +114,27 @@ cc_library(
103114
],
104115
)
105116

117+
cc_library(
118+
name = "span_context",
119+
srcs = [
120+
"internal/span_context.cc",
121+
"internal/span_id.cc",
122+
"internal/trace_id.cc",
123+
"internal/trace_options.cc",
124+
],
125+
hdrs = [
126+
"span_context.h",
127+
"span_id.h",
128+
"trace_id.h",
129+
"trace_options.h",
130+
],
131+
copts = DEFAULT_COPTS,
132+
visibility = ["//visibility:public"],
133+
deps = [
134+
"@com_google_absl//absl/strings",
135+
],
136+
)
137+
106138
cc_library(
107139
name = "with_span",
108140
srcs = ["internal/with_span.cc"],
@@ -150,6 +182,17 @@ cc_test(
150182
],
151183
)
152184

185+
cc_test(
186+
name = "cloud_trace_context_test",
187+
srcs = ["internal/cloud_trace_context_test.cc"],
188+
copts = TEST_COPTS,
189+
deps = [
190+
":cloud_trace_context",
191+
":span_context",
192+
"@com_google_googletest//:gtest_main",
193+
],
194+
)
195+
153196
cc_test(
154197
name = "context_util_test",
155198
srcs = ["internal/context_util_test.cc"],
@@ -168,6 +211,7 @@ cc_test(
168211
srcs = ["internal/link_test.cc"],
169212
copts = TEST_COPTS,
170213
deps = [
214+
":span_context",
171215
":trace",
172216
"@com_google_googletest//:gtest_main",
173217
],
@@ -188,6 +232,7 @@ cc_test(
188232
srcs = ["internal/running_span_store_test.cc"],
189233
copts = TEST_COPTS,
190234
deps = [
235+
":span_context",
191236
":trace",
192237
"@com_google_absl//absl/base:core_headers",
193238
"@com_google_absl//absl/memory",
@@ -212,6 +257,7 @@ cc_test(
212257
srcs = ["internal/span_test.cc"],
213258
copts = TEST_COPTS,
214259
deps = [
260+
":span_context",
215261
":trace",
216262
"@com_google_absl//absl/strings",
217263
"@com_google_googletest//:gtest_main",
@@ -223,7 +269,7 @@ cc_test(
223269
srcs = ["internal/span_id_test.cc"],
224270
copts = TEST_COPTS,
225271
deps = [
226-
":trace",
272+
":span_context",
227273
"@com_google_googletest//:gtest_main",
228274
],
229275
)
@@ -233,6 +279,7 @@ cc_test(
233279
srcs = ["internal/span_options_test.cc"],
234280
copts = TEST_COPTS,
235281
deps = [
282+
":span_context",
236283
":trace",
237284
"@com_google_absl//absl/strings",
238285
"@com_google_absl//absl/synchronization",
@@ -245,7 +292,7 @@ cc_test(
245292
srcs = ["internal/span_context_test.cc"],
246293
copts = TEST_COPTS,
247294
deps = [
248-
":trace",
295+
":span_context",
249296
"@com_google_googletest//:gtest_main",
250297
],
251298
)
@@ -289,7 +336,7 @@ cc_test(
289336
srcs = ["internal/trace_options_test.cc"],
290337
copts = TEST_COPTS,
291338
deps = [
292-
":trace",
339+
":span_context",
293340
"@com_google_googletest//:gtest_main",
294341
],
295342
)
@@ -299,6 +346,7 @@ cc_test(
299346
srcs = ["internal/with_span_test.cc"],
300347
copts = TEST_COPTS,
301348
deps = [
349+
":span_context",
302350
":trace",
303351
":with_span",
304352
"//opencensus/context",
@@ -314,22 +362,33 @@ cc_binary(
314362
testonly = 1,
315363
srcs = ["internal/attribute_value_ref_benchmark.cc"],
316364
copts = TEST_COPTS,
317-
linkopts = ["-pthread"], # Required for absl/synchronization bits.
318365
linkstatic = 1,
319366
deps = [
320367
":trace",
321368
"@com_github_google_benchmark//:benchmark",
322369
],
323370
)
324371

372+
cc_binary(
373+
name = "cloud_trace_context_benchmark",
374+
testonly = 1,
375+
srcs = ["internal/cloud_trace_context_benchmark.cc"],
376+
copts = TEST_COPTS,
377+
linkstatic = 1,
378+
deps = [
379+
":cloud_trace_context",
380+
"@com_github_google_benchmark//:benchmark",
381+
],
382+
)
383+
325384
cc_binary(
326385
name = "span_benchmark",
327386
testonly = 1,
328387
srcs = ["internal/span_benchmark.cc"],
329388
copts = TEST_COPTS,
330-
linkopts = ["-pthread"], # Required for absl/synchronization bits.
331389
linkstatic = 1,
332390
deps = [
391+
":span_context",
333392
":trace",
334393
"@com_github_google_benchmark//:benchmark",
335394
],
@@ -340,10 +399,9 @@ cc_binary(
340399
testonly = 1,
341400
srcs = ["internal/span_id_benchmark.cc"],
342401
copts = TEST_COPTS,
343-
linkopts = ["-pthread"], # Required for absl/synchronization bits.
344402
linkstatic = 1,
345403
deps = [
346-
":trace",
404+
":span_context",
347405
"@com_github_google_benchmark//:benchmark",
348406
],
349407
)
@@ -353,7 +411,6 @@ cc_binary(
353411
testonly = 1,
354412
srcs = ["internal/with_span_benchmark.cc"],
355413
copts = TEST_COPTS,
356-
linkopts = ["-pthread"], # Required for absl/synchronization bits.
357414
linkstatic = 1,
358415
deps = [
359416
":trace",

opencensus/trace/CMakeLists.txt

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,34 @@ opencensus_lib(trace
2828
internal/running_span_store_impl.cc
2929
internal/sampler.cc
3030
internal/span.cc
31-
internal/span_context.cc
3231
internal/span_data.cc
3332
internal/span_exporter.cc
3433
internal/span_exporter_impl.cc
35-
internal/span_id.cc
3634
internal/span_impl.cc
3735
internal/status.cc
3836
internal/trace_config.cc
3937
internal/trace_config_impl.cc
40-
internal/trace_id.cc
41-
internal/trace_options.cc
4238
internal/with_span.cc
4339
DEPS
4440
common_random
41+
trace_cloud_trace_context
42+
trace_span_context
4543
absl::strings
4644
absl::base
4745
absl::memory
4846
absl::synchronization
4947
absl::time
5048
absl::span)
5149

50+
opencensus_lib(trace_cloud_trace_context
51+
PUBLIC
52+
SRCS
53+
internal/cloud_trace_context.cc
54+
DEPS
55+
trace_span_context
56+
absl::base
57+
absl::strings)
58+
5259
opencensus_lib(trace_context_util
5360
PUBLIC
5461
SRCS
@@ -57,6 +64,16 @@ opencensus_lib(trace_context_util
5764
trace
5865
context)
5966

67+
opencensus_lib(trace_span_context
68+
PUBLIC
69+
SRCS
70+
internal/span_context.cc
71+
internal/span_id.cc
72+
internal/trace_id.cc
73+
internal/trace_options.cc
74+
DEPS
75+
absl::strings)
76+
6077
opencensus_lib(trace_with_span
6178
PUBLIC
6279
SRCS
@@ -77,6 +94,9 @@ opencensus_test(trace_attribute_value_ref_test
7794
opencensus_test(trace_attribute_value_test internal/attribute_value_test.cc
7895
trace)
7996

97+
opencensus_test(trace_cloud_trace_context_test
98+
internal/cloud_trace_context_test.cc trace_cloud_trace_context)
99+
80100
opencensus_test(trace_context_util_test
81101
internal/context_util_test.cc
82102
trace
@@ -118,7 +138,7 @@ opencensus_test(trace_span_options_test
118138

119139
opencensus_test(trace_span_context_test
120140
internal/span_context_test.cc
121-
trace
141+
trace_span_context
122142
absl::strings
123143
absl::span)
124144

0 commit comments

Comments
 (0)