Couchbase C++ SDK 1.3.1 (rev. fb3f860)
Loading...
Searching...
No Matches
otel_tracer.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright 2021 Couchbase, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
21
22#include <opentelemetry/trace/tracer.h>
23
25{
27{
28public:
29 explicit otel_request_span(opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> span)
30 : span_(std::move(span))
31 {
32 }
33 void add_tag(const std::string& name, const std::string& value) override
34 {
35 span_->SetAttribute(name, value);
36 }
37 void add_tag(const std::string& name, uint64_t value) override
38 {
39 span_->SetAttribute(name, value);
40 }
41 void end() override
42 {
43 span_->End();
44 }
45 auto wrapped_span() -> opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span>
46 {
47 return span_;
48 }
49
50private:
51 opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> span_;
52};
53
55{
56public:
58 opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> tracer)
59 : tracer_(std::move(tracer))
60 {
61 }
62
63 auto start_span(std::string name, std::shared_ptr<couchbase::tracing::request_span> parent)
64 -> std::shared_ptr<couchbase::tracing::request_span> override
65 {
66 const auto wrapped_parent = std::dynamic_pointer_cast<otel_request_span>(parent);
67 opentelemetry::trace::StartSpanOptions opts;
68 opts.kind = opentelemetry::trace::SpanKind::kClient;
69 if (wrapped_parent) {
70 opts.parent = wrapped_parent->wrapped_span()->GetContext();
71 }
72 return std::make_shared<otel_request_span>(tracer_->StartSpan(name, opts));
73 }
74
75 auto wrap_span(opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> span)
76 -> std::shared_ptr<couchbase::tracing::otel_request_span>
77 {
78 return std::make_shared<couchbase::tracing::otel_request_span>(std::move(span));
79 }
80
81private:
82 opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> tracer_;
83};
84} // namespace couchbase::tracing
void add_tag(const std::string &name, uint64_t value) override
Definition otel_tracer.hxx:37
auto wrapped_span() -> opentelemetry::nostd::shared_ptr< opentelemetry::trace::Span >
Definition otel_tracer.hxx:45
void end() override
Definition otel_tracer.hxx:41
otel_request_span(opentelemetry::nostd::shared_ptr< opentelemetry::trace::Span > span)
Definition otel_tracer.hxx:29
void add_tag(const std::string &name, const std::string &value) override
Definition otel_tracer.hxx:33
auto start_span(std::string name, std::shared_ptr< couchbase::tracing::request_span > parent) -> std::shared_ptr< couchbase::tracing::request_span > override
Definition otel_tracer.hxx:63
auto wrap_span(opentelemetry::nostd::shared_ptr< opentelemetry::trace::Span > span) -> std::shared_ptr< couchbase::tracing::otel_request_span >
Definition otel_tracer.hxx:75
otel_request_tracer(opentelemetry::nostd::shared_ptr< opentelemetry::trace::Tracer > tracer)
Definition otel_tracer.hxx:57
Definition request_span.hxx:27
auto name() const -> const std::string &
Definition request_span.hxx:49
Definition request_tracer.hxx:28
Definition otel_tracer.hxx:25
@ parent
Notify the context that the process has forked and is the parent.
Definition fork_event.hxx:31