-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Otlp http log example #1062
Merged
Merged
Otlp http log example #1062
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cb349d2
otlp http log export example
esigo 70b3359
format
esigo b8f856f
cmake
esigo c2c3bb2
ci bazel
esigo 4935ca4
readme
esigo 81d8a85
Merge branch 'main' into otlp-http-log-example
esigo c14c929
logger options
esigo 36e36ea
Merge branch 'otlp-http-log-example' of https://github.com/esigo/open…
esigo 1208a79
Merge branch 'main' into otlp-http-log-example
lalitb c11771b
Build opentelemetry-proto collector interface with cmake only if WITH…
lalitb 35db3fa
Merge branch 'otlp-http-log-example' of https://github.com/esigo/open…
esigo a6ce8fc
Merge branch 'main' into otlp-http-log-example
lalitb 32dbd02
Merge branch 'main' into otlp-http-log-example
esigo a400b7d
Merge branch 'otlp-http-log-example' of https://github.com/esigo/open…
esigo 2ead568
comments
esigo eb4b0a0
Merge branch 'main' into otlp-http-log-example
esigo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
add_subdirectory(foo_library) | ||
if(WITH_LOGS_PREVIEW) | ||
add_subdirectory(logs_foo_library) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cc_library( | ||
name = "common_logs_foo_library", | ||
srcs = [ | ||
"foo_library.cc", | ||
], | ||
hdrs = [ | ||
"foo_library.h", | ||
], | ||
defines = ["BAZEL_BUILD"], | ||
deps = [ | ||
"//api", | ||
"//sdk:headers", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add_library(common_logs_foo_library foo_library.h foo_library.cc) | ||
target_link_libraries(common_logs_foo_library PUBLIC ${CMAKE_THREAD_LIBS_INIT} | ||
opentelemetry_api) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#ifdef ENABLE_LOGS_PREVIEW | ||
# include <map> | ||
# include <string> | ||
# include "opentelemetry/logs/provider.h" | ||
# include "opentelemetry/sdk/version/version.h" | ||
# include "opentelemetry/trace/provider.h" | ||
|
||
namespace logs = opentelemetry::logs; | ||
namespace trace = opentelemetry::trace; | ||
namespace nostd = opentelemetry::nostd; | ||
|
||
namespace | ||
{ | ||
nostd::shared_ptr<trace::Tracer> get_tracer() | ||
{ | ||
auto provider = trace::Provider::GetTracerProvider(); | ||
return provider->GetTracer("foo_library", OPENTELEMETRY_SDK_VERSION); | ||
} | ||
|
||
nostd::shared_ptr<logs::Logger> get_logger() | ||
{ | ||
auto provider = logs::Provider::GetLoggerProvider(); | ||
return provider->GetLogger("foo_library_logger"); | ||
} | ||
} // namespace | ||
|
||
void foo_library() | ||
{ | ||
auto span = get_tracer()->StartSpan("span 1"); | ||
auto scoped_span = trace::Scope(get_tracer()->StartSpan("foo_library")); | ||
auto ctx = span->GetContext(); | ||
auto logger = get_logger(); | ||
logger->Log(opentelemetry::logs::Severity::kDebug, "name", "body", {}, {}, ctx.trace_id(), | ||
ctx.span_id(), ctx.trace_flags(), opentelemetry::common::SystemTimestamp()); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
void foo_library(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifdef ENABLE_LOGS_PREVIEW | ||
# include "opentelemetry/exporters/otlp/otlp_http_exporter.h" | ||
# include "opentelemetry/exporters/otlp/otlp_http_log_exporter.h" | ||
# include "opentelemetry/logs/provider.h" | ||
# include "opentelemetry/sdk/logs/logger_provider.h" | ||
# include "opentelemetry/sdk/logs/simple_log_processor.h" | ||
# include "opentelemetry/sdk/trace/simple_processor.h" | ||
# include "opentelemetry/sdk/trace/tracer_provider.h" | ||
# include "opentelemetry/trace/provider.h" | ||
|
||
# include <string> | ||
|
||
# ifdef BAZEL_BUILD | ||
# include "examples/common/logs_foo_library/foo_library.h" | ||
# else | ||
# include "logs_foo_library/foo_library.h" | ||
# endif | ||
|
||
namespace trace = opentelemetry::trace; | ||
namespace nostd = opentelemetry::nostd; | ||
namespace otlp = opentelemetry::exporter::otlp; | ||
namespace logs_sdk = opentelemetry::sdk::logs; | ||
namespace logs = opentelemetry::logs; | ||
namespace trace_sdk = opentelemetry::sdk::trace; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - use namespace alias as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
namespace | ||
{ | ||
|
||
opentelemetry::exporter::otlp::OtlpHttpExporterOptions opts; | ||
void InitTracer() | ||
{ | ||
// Create OTLP exporter instance | ||
auto exporter = std::unique_ptr<trace_sdk::SpanExporter>(new otlp::OtlpHttpExporter(opts)); | ||
auto processor = std::unique_ptr<trace_sdk::SpanProcessor>( | ||
new trace_sdk::SimpleSpanProcessor(std::move(exporter))); | ||
auto provider = | ||
nostd::shared_ptr<trace::TracerProvider>(new trace_sdk::TracerProvider(std::move(processor))); | ||
// Set the global trace provider | ||
trace::Provider::SetTracerProvider(provider); | ||
} | ||
|
||
opentelemetry::exporter::otlp::OtlpHttpLogExporterOptions logger_opts; | ||
void InitLogger() | ||
{ | ||
logger_opts.console_debug = true; | ||
// Create OTLP exporter instance | ||
auto exporter = | ||
std::unique_ptr<logs_sdk::LogExporter>(new otlp::OtlpHttpLogExporter(logger_opts)); | ||
auto processor = std::shared_ptr<logs_sdk::LogProcessor>( | ||
new logs_sdk::SimpleLogProcessor(std::move(exporter))); | ||
auto sdkProvider = std::shared_ptr<logs_sdk::LoggerProvider>(new logs_sdk::LoggerProvider()); | ||
sdkProvider->SetProcessor(processor); | ||
auto apiProvider = nostd::shared_ptr<logs::LoggerProvider>(sdkProvider); | ||
auto provider = nostd::shared_ptr<logs::LoggerProvider>(apiProvider); | ||
opentelemetry::logs::Provider::SetLoggerProvider(provider); | ||
} | ||
} // namespace | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
if (argc > 1) | ||
{ | ||
opts.url = argv[1]; | ||
logger_opts.url = argv[1]; | ||
if (argc > 2) | ||
{ | ||
std::string debug = argv[2]; | ||
opts.console_debug = debug != "" && debug != "0" && debug != "no"; | ||
} | ||
|
||
if (argc > 3) | ||
{ | ||
std::string binary_mode = argv[3]; | ||
if (binary_mode.size() >= 3 && binary_mode.substr(0, 3) == "bin") | ||
{ | ||
opts.content_type = opentelemetry::exporter::otlp::HttpRequestContentType::kBinary; | ||
logger_opts.content_type = opentelemetry::exporter::otlp::HttpRequestContentType::kBinary; | ||
} | ||
} | ||
} | ||
InitLogger(); | ||
InitTracer(); | ||
foo_library(); | ||
} | ||
#else | ||
int main() | ||
{ | ||
return 0; | ||
} | ||
#endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need sdk::headers, I see this included in earlier PRs too so probably I am missing something :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's needed for
"opentelemetry/sdk/version/version.h"
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, thanks for letting me know. Not related to this PR, but we may have to revisit this afterward as ideally instrumentation libraries should have no dependency on SDK.