Skip to content
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

Support ContextManager APIs and context stack-style auto propagation. #3

Merged
merged 5 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[workspace]

members = [
"tracing-core",
"core",
]
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,43 @@ manipulate the RPC header/metadata to make the key/value sent to the server side

## Extractable
Extractable is used(optional) when the entry span creates. The Extractable fetches the value of the given key from the propagated
context. Typically, Extractable implementation would read the RPC header/metadata, which sent from the client side.
context. Typically, Extractable implementation would read the RPC header/metadata, which sent from the client side.

# APIs
## Tracing Core APIs
## High-Level APIs
High level APIs are targeting convenient usages. These APIs use the ThreadLocal to propagate the context, so users could
create span at any moment, and the context will finish automatically once the first created span of this thread stopped.

```rust
ContextManager::tracing_entry("op1", Some(&injector), |mut span| {
// Use span freely in this closure
// Span's start/end time is set automatically with this closure start/end(s).
span.tag(Tag::new(String::from("tag1"), String::from("value1")));

ContextManager::tracing_exit("op2", "127.0.0.1:8080", Some(&extractor), |mut span| {
span.set_component_id(33);
});

ContextManager::tracing_local("op3", |mut span| {});
});
```

## Low-Level Core APIs
Tracing core APIs are 100% manual control tracing APIs. Users could use them to trace any process by following SkyWalking
core concepts.

Low Level APIs request users to create and hold the context and span by the codes manually.

```rust
let mut context = TracingContext::new(&reporter).unwrap();
let span1 = context.create_entry_span("op1", None, Some(&MockerHeader {}));
let mut context = TracingContext::new(reporter.service_instance_id()).unwrap();
let span1 = context.create_entry_span("op1", None, Some(&dyn injector));
{
assert_eq!(span1.span_id(), 0);
let mut span2 = context.create_local_span("op2", Some(&span1));
span2.tag(Tag::new(String::from("tag1"), String::from("value1")));
{
assert_eq!(span2.span_id(), 1);
let mut span3 = context.create_exit_span("op3", Some(&span2), "127.0.0.1:8080", Some(&HeaderCarrier {}));
let mut span3 = context.create_exit_span("op3", Some(&span2), "127.0.0.1:8080", Some(&dyn extractor));
assert_eq!(span3.span_id(), 2);

context.finish_span(span3);
Expand Down
27 changes: 27 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[package]
name = "skywalking-core"
version = "0.1.0"
authors = ["Apache Software Foundation (ASF)"]
edition = "2018"
description = "SkyWalking tracing core APIs. Provide the way to build SkyWalking native format traces/spans and propagated context."
license = "Apache 2.0"

[dependencies]
rand = "0.7.3"
base64 = "0.11.0"
lazy_static = "1.4.0"
17 changes: 17 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod skywalking;

Loading