From 75ccc8370caa5622150dd580bf1699396a4c276d Mon Sep 17 00:00:00 2001 From: Juliano Costa Date: Fri, 16 Feb 2024 13:33:09 +0100 Subject: [PATCH 1/2] Add logs instructions to currencyservice --- content/en/docs/demo/services/currency.md | 46 ++++++++++++++++++----- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/content/en/docs/demo/services/currency.md b/content/en/docs/demo/services/currency.md index 1c4df3e7208b..7ef157fdaed7 100644 --- a/content/en/docs/demo/services/currency.md +++ b/content/en/docs/demo/services/currency.md @@ -52,7 +52,7 @@ std::string span_name = "CurrencyService/Convert"; auto span = get_tracer("currencyservice")->StartSpan(span_name, {{SemanticConventions::kRpcSystem, "grpc"}, - {SemanticConventions::kRpcService, "CurrencyService"}, + {SemanticConventions::kRpcService, "oteldemo.CurrencyService"}, {SemanticConventions::kRpcMethod, "Convert"}, {SemanticConventions::kRpcGrpcStatusCode, 0}}, options); @@ -144,20 +144,14 @@ The OpenTelemetry `MeterProvider` is initialized from `main()` using the `initMeter()` function defined in `meter_common.h`. ```cpp -void initMeter() +void initMeter() { // Build MetricExporter otlp_exporter::OtlpGrpcMetricExporterOptions otlpOptions; - - // Configuration via environment variable not supported yet - otlpOptions.endpoint = "otelcol:4317"; - otlpOptions.aggregation_temporality = metric_sdk::AggregationTemporality::kDelta; auto exporter = otlp_exporter::OtlpGrpcMetricExporterFactory::Create(otlpOptions); // Build MeterProvider and Reader metric_sdk::PeriodicExportingMetricReaderOptions options; - options.export_interval_millis = std::chrono::milliseconds(1000); - options.export_timeout_millis = std::chrono::milliseconds(500); std::unique_ptr reader{ new metric_sdk::PeriodicExportingMetricReader(std::move(exporter), options) }; auto provider = std::shared_ptr(new metric_sdk::MeterProvider()); @@ -205,4 +199,38 @@ CurrencyCounter(to_code); ## Logs -TBD +The OpenTelemetry `LoggerProvider` is initialized from `main()` using the +`initLogger()` function defined in `logger_common.h`. + +```cpp +void initLogger() { + otlp::OtlpGrpcLogRecordExporterOptions loggerOptions; + auto exporter = otlp::OtlpGrpcLogRecordExporterFactory::Create(loggerOptions); + auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter)); + std::vector> processors; + processors.push_back(std::move(processor)); + auto context = logs_sdk::LoggerContextFactory::Create(std::move(processors)); + std::shared_ptr provider = logs_sdk::LoggerProviderFactory::Create(std::move(context)); + opentelemetry::logs::Provider::SetLoggerProvider(provider); +} +``` + +### Using the LoggerProvider + +The initialized Logger Provider is called from `main` in `server.cpp`: + +```cpp +logger = getLogger(name); +``` + +It assigns the logger to a local variable called `logger`: + +```cpp +nostd::shared_ptr logger; +``` + +Which is then used throughout the code whenever we need to log a line: + +```cpp +logger->Info(std::string(__func__) + " conversion successful"); +``` From f148b56cf9ef52d909485adf116c3cc40214e983 Mon Sep 17 00:00:00 2001 From: Juliano Costa Date: Fri, 16 Feb 2024 13:35:33 +0100 Subject: [PATCH 2/2] remove space --- content/en/docs/demo/services/currency.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/en/docs/demo/services/currency.md b/content/en/docs/demo/services/currency.md index 7ef157fdaed7..61eb0f9141f8 100644 --- a/content/en/docs/demo/services/currency.md +++ b/content/en/docs/demo/services/currency.md @@ -144,7 +144,7 @@ The OpenTelemetry `MeterProvider` is initialized from `main()` using the `initMeter()` function defined in `meter_common.h`. ```cpp -void initMeter() +void initMeter() { // Build MetricExporter otlp_exporter::OtlpGrpcMetricExporterOptions otlpOptions;