Skip to content

Commit

Permalink
Initial sketch of span_id, example, and build.
Browse files Browse the repository at this point in the history
  • Loading branch information
g-easy committed Dec 19, 2019
1 parent 73fd549 commit e57940a
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 1 deletion.
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Only needed for tests, not to build the OpenTelemetry library.
http_archive(
name = "com_google_googletest",
sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",
strip_prefix = "googletest-release-1.10.0",
urls = ["https://github.com/google/googletest/archive/release-1.10.0.tar.gz"],
)
14 changes: 14 additions & 0 deletions api/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# 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.

package(default_visibility = ["//visibility:public"])

cc_library(
Expand Down
56 changes: 56 additions & 0 deletions api/include/opentelemetry/trace/span_id.h
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
7 changes: 7 additions & 0 deletions examples/README.md
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 removed examples/TBD
Empty file.
21 changes: 21 additions & 0 deletions examples/WORKSPACE
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 = "../",
)
21 changes: 21 additions & 0 deletions examples/helloworld/BUILD
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",
],
)
25 changes: 25 additions & 0 deletions examples/helloworld/helloworld.cc
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";
}
2 changes: 1 addition & 1 deletion tools/setup-buildtools-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# control of the brew dirs. That causes the brew update to fail.
# Temporarily allow the user to take over control of brew files.

echo ***
echo ***
echo *** You may need to enter your admin password to update the brew files:
echo ***

Expand Down

0 comments on commit e57940a

Please sign in to comment.