-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial sketch of span_id, example, and build.
- Loading branch information
Showing
9 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2019, OpenTelemetry Authors | ||
// | ||
// Licensed 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. | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <cstring> | ||
#include <string> | ||
|
||
namespace opentelemetry | ||
{ | ||
namespace trace | ||
{ | ||
|
||
class SpanId final | ||
{ | ||
public: | ||
// The size in bytes of the SpanId. | ||
static constexpr int kSize = 8; | ||
|
||
// An invalid SpanId (all zeros). | ||
SpanId() : rep_{0} {} | ||
|
||
// Creates a SpanId by copying the first kSize bytes from the buffer. | ||
explicit SpanId(const uint8_t *buf) { memcpy(rep_, buf, kSize); } | ||
|
||
// Returns a 16-char hex string of the SpanId value. | ||
std::string ToHex() const | ||
{ | ||
constexpr char kHex[] = "0123456789ABCDEF"; | ||
std::string s(kSize * 2, ' '); | ||
for (int i = 0; i < kSize; ++i) | ||
{ | ||
s[i * 2 + 0] = kHex[(rep_[i] >> 4) & 0xF]; | ||
s[i * 2 + 1] = kHex[(rep_[i] >> 0) & 0xF]; | ||
} | ||
return s; | ||
} | ||
|
||
private: | ||
uint8_t rep_[kSize]; | ||
}; | ||
|
||
} // namespace trace | ||
} // namespace opentelemetry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
The examples/ directory is a separate bazel workspace, to show how | ||
to build libraries and binaries that use the OpenTelemetry library. | ||
|
||
``` | ||
cd examples/ | ||
bazel build //helloworld | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2019, OpenTelemetry Authors | ||
# | ||
# Licensed 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(name = "io_opentelemetry_cpp_examples") | ||
|
||
# OpenTelemetry should be imported via http_archive. | ||
local_repository( | ||
name = "io_opentelemetry_cpp", | ||
path = "../", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2019, OpenTelemetry Authors | ||
# | ||
# Licensed 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. | ||
|
||
cc_binary( | ||
name = "helloworld", | ||
srcs = ["helloworld.cc"], | ||
deps = [ | ||
"@io_opentelemetry_cpp//api", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2019, OpenTelemetry Authors | ||
// | ||
// Licensed 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. | ||
|
||
#include <opentelemetry/trace/span_id.h> | ||
|
||
#include <cstdint> | ||
#include <iostream> | ||
|
||
int main() | ||
{ | ||
constexpr uint8_t id[] = {1, 2, 3, 4, 0x50, 0x60, 0x70, 0x80}; | ||
opentelemetry::trace::SpanId span_id(id); | ||
std::cout << "Span ID: '" << span_id.ToHex() << "'\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters