skywalking_rust/context/propagation/
context.rs

1// Licensed to the Apache Software Foundation (ASF) under one or more
2// contributor license agreements.  See the NOTICE file distributed with
3// this work for additional information regarding copyright ownership.
4// The ASF licenses this file to You under the Apache License, Version 2.0
5// (the "License"); you may not use this file except in compliance with
6// the License.  You may obtain a copy of the License at
7//
8//     http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17pub static SKYWALKING_HTTP_CONTEXT_HEADER_KEY: &str = "sw8";
18
19pub struct PropagationContext {
20    /// It defines whether next span should be trace or not.
21    /// In SkyWalking, If `do_sample == true`, the span should be reported to
22    /// OAP server and can be analyzed.
23    pub do_sample: bool,
24
25    /// It defines trace ID that previous span has. It expresses unique value of entire trace.
26    pub parent_trace_id: String,
27
28    /// It defines segment ID that previos span has. It expresses unique value of entire trace.
29    pub parent_trace_segment_id: String,
30
31    /// It defines parent span's span ID.
32    pub parent_span_id: i32,
33
34    /// Service name of service parent belongs.
35    pub parent_service: String,
36
37    /// Instance name of service parent belongs.
38    pub parent_service_instance: String,
39
40    /// An endpoint name that parent requested to.
41    pub destination_endpoint: String,
42
43    /// An address that parent requested to. It can be authority or network address.
44    pub destination_address: String,
45}
46
47/// PropagationContext carries the context which include trace infomation.
48/// In general, this context will be used if you create new TraceContext after received
49/// decoded context that should be packed in `sw8` header.
50impl PropagationContext {
51    #[allow(clippy::too_many_arguments)]
52    pub fn new(
53        do_sample: bool,
54        parent_trace_id: String,
55        parent_trace_segment_id: String,
56        parent_span_id: i32,
57        parent_service: String,
58        parent_service_instance: String,
59        destination_endpoint: String,
60        destination_address: String,
61    ) -> PropagationContext {
62        PropagationContext {
63            do_sample,
64            parent_trace_id,
65            parent_trace_segment_id,
66            parent_span_id,
67            parent_service,
68            parent_service_instance,
69            destination_endpoint,
70            destination_address,
71        }
72    }
73}