|
| 1 | +// Copyright 2024 FastLabs Developers |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +use fastrace::collector::Config; |
| 16 | +use fastrace::collector::ConsoleReporter; |
| 17 | +use fastrace::collector::SpanContext; |
| 18 | +use fastrace::prelude::SpanId; |
| 19 | +use fastrace::prelude::TraceId; |
| 20 | +use fastrace::Span; |
| 21 | +use logforth::append; |
| 22 | +use logforth::diagnostic; |
| 23 | +use logforth::layout::GoogleStructuredLogLayout; |
| 24 | +use serde::Serialize; |
| 25 | + |
| 26 | +#[derive(Serialize)] |
| 27 | +struct NestedStructuredValue { |
| 28 | + c: String, |
| 29 | + d: bool, |
| 30 | +} |
| 31 | + |
| 32 | +#[derive(Serialize)] |
| 33 | +struct MyStructuredValue { |
| 34 | + a: i32, |
| 35 | + b: NestedStructuredValue, |
| 36 | +} |
| 37 | + |
| 38 | +fn main() { |
| 39 | + logforth::builder() |
| 40 | + .dispatch(|d| { |
| 41 | + d.diagnostic(diagnostic::FastraceDiagnostic::default()) |
| 42 | + .append( |
| 43 | + append::Stdout::default().with_layout( |
| 44 | + GoogleStructuredLogLayout::default() |
| 45 | + .trace_project_id("project-id") |
| 46 | + .label_keys(["label1"]), |
| 47 | + ), |
| 48 | + ) |
| 49 | + }) |
| 50 | + .apply(); |
| 51 | + |
| 52 | + fastrace::set_reporter(ConsoleReporter, Config::default()); |
| 53 | + |
| 54 | + { |
| 55 | + let root = Span::root("root", SpanContext::new(TraceId::random(), SpanId(0))); |
| 56 | + let _g = root.set_local_parent(); |
| 57 | + |
| 58 | + let structured_value = MyStructuredValue { |
| 59 | + a: 1, |
| 60 | + b: NestedStructuredValue { |
| 61 | + c: "Hello".into(), |
| 62 | + d: true, |
| 63 | + }, |
| 64 | + }; |
| 65 | + |
| 66 | + log::info!( |
| 67 | + label1 = "this is a label value", |
| 68 | + notLabel:serde = structured_value; |
| 69 | + "Hello label value!", |
| 70 | + ); |
| 71 | + } |
| 72 | +} |
0 commit comments