-
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 gRPC log example #1083
Merged
Merged
Otlp gRPC log example #1083
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b312e8e
otlp grpc log export example
esigo 179fb2f
Merge branch 'open-telemetry:main' into otlp-grpc-log-exampe
esigo 0f5261c
otlp grpc log export example
esigo e11bcb3
Merge branch 'otlp-grpc-log-example' of https://github.com/esigo/open…
esigo 9565a9d
revert json
esigo 0f5d964
revert submodule
esigo a037e26
namespace
esigo 3fd976d
Merge branch 'open-telemetry:main' into otlp-grpc-log-example
esigo 89e9d6e
comments
esigo 72b708f
format
esigo 86d4fc9
md file
esigo 3a330c5
Merge branch 'main' into otlp-grpc-log-example
esigo c76f054
Merge branch 'main' into otlp-grpc-log-example
esigo 43125ee
Merge branch 'main' into otlp-grpc-log-example
ThomsonTan 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
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,79 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifdef ENABLE_LOGS_PREVIEW | ||
# include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h" | ||
# include "opentelemetry/exporters/otlp/otlp_grpc_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; | ||
|
||
ThomsonTan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
namespace trace_sdk = opentelemetry::sdk::trace; | ||
|
||
namespace | ||
{ | ||
opentelemetry::exporter::otlp::OtlpGrpcExporterOptions opts; | ||
void InitTracer() | ||
{ | ||
// Create OTLP exporter instance | ||
auto exporter = std::unique_ptr<trace_sdk::SpanExporter>(new otlp::OtlpGrpcExporter(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); | ||
} | ||
|
||
void InitLogger() | ||
{ | ||
// Create OTLP exporter instance | ||
auto exporter = std::unique_ptr<logs_sdk::LogExporter>(new otlp::OtlpGrpcLogExporter(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.endpoint = argv[1]; | ||
if (argc > 2) | ||
{ | ||
opts.use_ssl_credentials = true; | ||
opts.ssl_credentials_cacert_path = argv[2]; | ||
} | ||
} | ||
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.
nit: fix period in line 9 and 10, or fix the whole sentence from line 7 to 10.
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.
done