Couchbase C++ SDK
1.4.0 (rev. 59aa900)
Toggle main menu visibility
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
20
#include <
couchbase/tracing/request_tracer.hxx
>
21
22
#include <opentelemetry/trace/tracer.h>
23
24
namespace
couchbase::tracing
25
{
26
class
otel_request_span
:
public
couchbase::tracing::request_span
27
{
28
public
:
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
50
private
:
51
opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> span_;
52
};
53
54
class
otel_request_tracer
:
public
couchbase::tracing::request_tracer
55
{
56
public
:
57
explicit
otel_request_tracer
(
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
81
private
:
82
opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> tracer_;
83
};
84
}
// namespace couchbase::tracing
couchbase::tracing::otel_request_span::add_tag
void add_tag(const std::string &name, uint64_t value) override
Definition
otel_tracer.hxx:37
couchbase::tracing::otel_request_span::wrapped_span
auto wrapped_span() -> opentelemetry::nostd::shared_ptr< opentelemetry::trace::Span >
Definition
otel_tracer.hxx:45
couchbase::tracing::otel_request_span::end
void end() override
Definition
otel_tracer.hxx:41
couchbase::tracing::otel_request_span::otel_request_span
otel_request_span(opentelemetry::nostd::shared_ptr< opentelemetry::trace::Span > span)
Definition
otel_tracer.hxx:29
couchbase::tracing::otel_request_span::add_tag
void add_tag(const std::string &name, const std::string &value) override
Definition
otel_tracer.hxx:33
couchbase::tracing::otel_request_tracer::start_span
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
couchbase::tracing::otel_request_tracer::wrap_span
auto wrap_span(opentelemetry::nostd::shared_ptr< opentelemetry::trace::Span > span) -> std::shared_ptr< couchbase::tracing::otel_request_span >
Definition
otel_tracer.hxx:75
couchbase::tracing::otel_request_tracer::otel_request_tracer
otel_request_tracer(opentelemetry::nostd::shared_ptr< opentelemetry::trace::Tracer > tracer)
Definition
otel_tracer.hxx:57
couchbase::tracing::request_span
Definition
request_span.hxx:27
couchbase::tracing::request_span::name
auto name() const -> const std::string &
Definition
request_span.hxx:49
couchbase::tracing::request_tracer
Definition
request_tracer.hxx:28
couchbase::tracing
Definition
otel_tracer.hxx:25
couchbase::fork_event::parent
@ parent
Notify the context that the process has forked and is the parent.
Definition
fork_event.hxx:31
request_tracer.hxx
couchbase
tracing
otel_tracer.hxx
Generated by
1.17.0