diff --git a/config/config.md b/config/config.md index 14e3e61235..fcd23a2b5f 100644 --- a/config/config.md +++ b/config/config.md @@ -192,7 +192,8 @@ | `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. | | `logging.max_log_files` | Integer | `720` | The maximum amount of log files. | | `logging.otlp_export_protocol` | String | `http` | The OTLP tracing export protocol. Can be `grpc`/`http`. | -| `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | +| `logging.otlp_headers` | -- | -- | Additional OTLP headers, only valid when using OTLP http | +| `logging.tracing_sample_ratio` | -- | Unset | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | | `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- | | `slow_query` | -- | -- | The slow query log options. | | `slow_query.enable` | Bool | `false` | Whether to enable slow query log. | @@ -300,7 +301,8 @@ | `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. | | `logging.max_log_files` | Integer | `720` | The maximum amount of log files. | | `logging.otlp_export_protocol` | String | `http` | The OTLP tracing export protocol. Can be `grpc`/`http`. | -| `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | +| `logging.otlp_headers` | -- | -- | Additional OTLP headers, only valid when using OTLP http | +| `logging.tracing_sample_ratio` | -- | Unset | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | | `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- | | `slow_query` | -- | -- | The slow query log options. | | `slow_query.enable` | Bool | `true` | Whether to enable slow query log. | @@ -399,7 +401,8 @@ | `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. | | `logging.max_log_files` | Integer | `720` | The maximum amount of log files. | | `logging.otlp_export_protocol` | String | `http` | The OTLP tracing export protocol. Can be `grpc`/`http`. | -| `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | +| `logging.otlp_headers` | -- | -- | Additional OTLP headers, only valid when using OTLP http | +| `logging.tracing_sample_ratio` | -- | Unset | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | | `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- | | `export_metrics` | -- | -- | The metasrv can export its metrics and send to Prometheus compatible service (e.g. `greptimedb` itself) from remote-write API.
This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape. | | `export_metrics.enable` | Bool | `false` | whether enable export metrics. | @@ -567,7 +570,8 @@ | `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. | | `logging.max_log_files` | Integer | `720` | The maximum amount of log files. | | `logging.otlp_export_protocol` | String | `http` | The OTLP tracing export protocol. Can be `grpc`/`http`. | -| `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | +| `logging.otlp_headers` | -- | -- | Additional OTLP headers, only valid when using OTLP http | +| `logging.tracing_sample_ratio` | -- | Unset | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | | `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- | | `export_metrics` | -- | -- | The datanode can export its metrics and send to Prometheus compatible service (e.g. `greptimedb` itself) from remote-write API.
This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape. | | `export_metrics.enable` | Bool | `false` | whether enable export metrics. | @@ -636,7 +640,8 @@ | `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. | | `logging.max_log_files` | Integer | `720` | The maximum amount of log files. | | `logging.otlp_export_protocol` | String | `http` | The OTLP tracing export protocol. Can be `grpc`/`http`. | -| `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | +| `logging.otlp_headers` | -- | -- | Additional OTLP headers, only valid when using OTLP http | +| `logging.tracing_sample_ratio` | -- | Unset | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | | `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- | | `tracing` | -- | -- | The tracing options. Only effect when compiled with `tokio-console` feature. | | `tracing.tokio_console_addr` | String | Unset | The tokio console address. | diff --git a/config/datanode.example.toml b/config/datanode.example.toml index 02c6d9e076..b1af1755e4 100644 --- a/config/datanode.example.toml +++ b/config/datanode.example.toml @@ -646,6 +646,13 @@ max_log_files = 720 ## The OTLP tracing export protocol. Can be `grpc`/`http`. otlp_export_protocol = "http" +## Additional OTLP headers, only valid when using OTLP http +[logging.otlp_headers] +## @toml2docs:none-default +#Authorization = "Bearer my-token" +## @toml2docs:none-default +#Database = "My database" + ## The percentage of tracing will be sampled and exported. ## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1. ## ratio > 1 are treated as 1. Fractions < 0 are treated as 0 diff --git a/config/flownode.example.toml b/config/flownode.example.toml index 2db7dd79b9..81ff25f283 100644 --- a/config/flownode.example.toml +++ b/config/flownode.example.toml @@ -134,6 +134,13 @@ max_log_files = 720 ## The OTLP tracing export protocol. Can be `grpc`/`http`. otlp_export_protocol = "http" +## Additional OTLP headers, only valid when using OTLP http +[logging.otlp_headers] +## @toml2docs:none-default +#Authorization = "Bearer my-token" +## @toml2docs:none-default +#Database = "My database" + ## The percentage of tracing will be sampled and exported. ## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1. ## ratio > 1 are treated as 1. Fractions < 0 are treated as 0 diff --git a/config/frontend.example.toml b/config/frontend.example.toml index 695808251a..b2b1c598b0 100644 --- a/config/frontend.example.toml +++ b/config/frontend.example.toml @@ -237,6 +237,13 @@ max_log_files = 720 ## The OTLP tracing export protocol. Can be `grpc`/`http`. otlp_export_protocol = "http" +## Additional OTLP headers, only valid when using OTLP http +[logging.otlp_headers] +## @toml2docs:none-default +#Authorization = "Bearer my-token" +## @toml2docs:none-default +#Database = "My database" + ## The percentage of tracing will be sampled and exported. ## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1. ## ratio > 1 are treated as 1. Fractions < 0 are treated as 0 diff --git a/config/metasrv.example.toml b/config/metasrv.example.toml index 8e65152ade..fc9b8a8ef4 100644 --- a/config/metasrv.example.toml +++ b/config/metasrv.example.toml @@ -292,6 +292,14 @@ max_log_files = 720 ## The OTLP tracing export protocol. Can be `grpc`/`http`. otlp_export_protocol = "http" +## Additional OTLP headers, only valid when using OTLP http +[logging.otlp_headers] +## @toml2docs:none-default +#Authorization = "Bearer my-token" +## @toml2docs:none-default +#Database = "My database" + + ## The percentage of tracing will be sampled and exported. ## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1. ## ratio > 1 are treated as 1. Fractions < 0 are treated as 0 diff --git a/config/standalone.example.toml b/config/standalone.example.toml index 5e90100bbb..e93d66a135 100644 --- a/config/standalone.example.toml +++ b/config/standalone.example.toml @@ -738,6 +738,13 @@ max_log_files = 720 ## The OTLP tracing export protocol. Can be `grpc`/`http`. otlp_export_protocol = "http" +## Additional OTLP headers, only valid when using OTLP http +[logging.otlp_headers] +## @toml2docs:none-default +#Authorization = "Bearer my-token" +## @toml2docs:none-default +#Database = "My database" + ## The percentage of tracing will be sampled and exported. ## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1. ## ratio > 1 are treated as 1. Fractions < 0 are treated as 0 diff --git a/src/common/telemetry/src/logging.rs b/src/common/telemetry/src/logging.rs index 92af20dcd4..09cd9c3ef6 100644 --- a/src/common/telemetry/src/logging.rs +++ b/src/common/telemetry/src/logging.rs @@ -13,6 +13,7 @@ // limitations under the License. //! logging stuffs, inspired by databend +use std::collections::HashMap; use std::env; use std::io::IsTerminal; use std::sync::{Arc, Mutex, Once}; @@ -22,7 +23,7 @@ use common_base::serde::empty_string_as_default; use once_cell::sync::{Lazy, OnceCell}; use opentelemetry::trace::TracerProvider; use opentelemetry::{global, KeyValue}; -use opentelemetry_otlp::{Protocol, SpanExporter, WithExportConfig}; +use opentelemetry_otlp::{Protocol, SpanExporter, WithExportConfig, WithHttpConfig}; use opentelemetry_sdk::propagation::TraceContextPropagator; use opentelemetry_sdk::trace::Sampler; use opentelemetry_semantic_conventions::resource; @@ -82,6 +83,10 @@ pub struct LoggingOptions { /// The protocol of OTLP export. pub otlp_export_protocol: Option, + + /// Additional HTTP headers for OTLP exporter. + #[serde(skip_serializing_if = "HashMap::is_empty")] + pub otlp_headers: HashMap, } /// The protocol of OTLP export. @@ -176,6 +181,7 @@ impl Default for LoggingOptions { // Rotation hourly, 24 files per day, keeps info log files of 30 days max_log_files: 720, otlp_export_protocol: None, + otlp_headers: HashMap::new(), } } } @@ -469,6 +475,7 @@ fn build_otlp_exporter(opts: &LoggingOptions) -> SpanExporter { .with_http() .with_endpoint(endpoint) .with_protocol(Protocol::HttpBinary) + .with_headers(opts.otlp_headers.clone()) .build() .expect("Failed to create OTLP HTTP exporter "), }