Skip to content

Instantly share code, notes, and snippets.

View carlosalberto's full-sized avatar
🏠
Working from home

Carlos Alberto Cortez carlosalberto

🏠
Working from home
View GitHub Profile
import java.util.GlobalTracer;
public static void Main() {
// Don't create any extra objects, unless needed.
GlobalTracer.registerIfAbsent(TracerCallable.INSTANCE);
Span span = GlobalTracer.get().buildSpan("myOperation").start();
}
class TracerCallable implements Callable<Tracer> {
py37-test-api run-test: commands[0] | pytest
=================================================================================== test session starts ====================================================================================
platform darwin -- Python 3.7.4, pytest-6.1.0, py-1.9.0, pluggy-0.13.1 -- /development/opentelemetry-python/.tox/py37-test-api/bin/python
cachedir: .tox/py37-test-api/.pytest_cache
rootdir: /development/opentelemetry-python, configfile: pyproject.toml
collected 0 items / 1 error
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Traceback (most recent call last):
File "/development/opentelemetry-python/.tox/py37-test-api/bin/pytest", line 11, in <module>
sys.exit(console_main())
import opentelemetry.context.Scope;
import opentelemetry.trace.Tracer;
import opentelemetry.trace.Span;
# No imports on Brave
// Start a new trace or a span within an existing trace representing an operation
Span span = tracer.spanBuilder("encode").startSpan();
// Put the span in "scope" so that downstream code such as loggers can see trace IDs
try (Scope scope = tracer.withSpan(span)) {
return encoder.encode();
# Get the ls-examples repo
git clone https://github.com/lightstep/ls-examples
cd ls-examples
# Use the launcher-java branch
git checkout otel-launcher-java
# Jump to the specific example
cd java/launcher
/*
* 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
// ------------- Context API --------------
// Based on top of grpc.Context
// (We could also use it directly and add the automatic Scope handling).
// Note: Cannot use String directly for the keys, as an imposition done
// by grpc.Context.
// Questions:
// - Should we allow some form of extensibility to allow
// users to provide logic/storage?
public final class Context {
// FOLLOWS_FROM use scenario.
public class Promise<T> {
public Promise() {
// 1. Capture the active Span.
this.parentSpan = tracer.activeSpan();
}
// 2. Add callacks that will be invoked asynchronously
// upon success.
Span context = span.context();
String traceId = context.toTraceId();
String spanId = context.toSpanId();
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.340 s
[INFO] Finished at: 2019-02-26T19:52:21+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project opentracing-specialagent: Could not resolve dependencies for project io.opentracing.contrib:opentracing-specialagent:jar:0.0.1-SNAPSHOT: Could not find artifact io.opentracing.contrib:opentracing-specialagent-jms2:jar:0.0.1-SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
Scope scope = null;
try {
scope = tracer.buildSpan("foo").startActive();
} catch (Exception exc) {
Tags.ERROR.set(scope.span(), true);
scope.span().log(ImmutableMap.Builder<String, Object>()
.put("event", "error")
.put("error.object", exc)
.build());