blob: 2281bdcc05bf4ccfc8bfd22d02898c5ef766b3e3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include <spdlog/sinks/sink.h>
#include <zencore/zencore.h>
#include <zenhttp/httpclient.h>
#include <zentelemetry/otlpencoder.h>
#include <zentelemetry/otlptrace.h>
#if ZEN_WITH_OTEL
namespace zen::logging {
/**
* OTLP/HTTP sink for spdlog
*
* Sends log messages and traces to an OpenTelemetry collector via OTLP over HTTP
*/
class OtelHttpProtobufSink : public spdlog::sinks::sink
{
public:
// Note that this URI should be the base URI of the OTLP HTTP endpoint, e.g.
// "http://otel-collector:4318"
OtelHttpProtobufSink(const std::string_view& Uri);
~OtelHttpProtobufSink();
OtelHttpProtobufSink(const OtelHttpProtobufSink&) = delete;
OtelHttpProtobufSink& operator=(const OtelHttpProtobufSink&) = delete;
private:
virtual void log(const spdlog::details::log_msg& Msg) override;
virtual void flush() override;
virtual void set_pattern(const std::string& pattern) override { ZEN_UNUSED(pattern); }
virtual void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override { ZEN_UNUSED(sink_formatter); }
void RecordSpans(zen::otel::TraceId Trace, std::span<const zen::otel::Span*> Spans);
// This is just a thin wrapper to call back into the sink while participating in
// reference counting from the OTEL trace back-end
class TraceRecorder : public zen::otel::TraceRecorder
{
public:
TraceRecorder(OtelHttpProtobufSink* InSink) : m_Sink(InSink) {}
private:
TraceRecorder(const TraceRecorder&) = delete;
TraceRecorder& operator=(const TraceRecorder&) = delete;
virtual void RecordSpans(zen::otel::TraceId Trace, std::span<const zen::otel::Span*> Spans) override;
OtelHttpProtobufSink* m_Sink;
};
HttpClient m_OtelHttp;
OtlpEncoder m_Encoder;
Ref<TraceRecorder> m_TraceRecorder;
};
} // namespace zen::logging
#endif
|