Skip to content

Commit 1b93f76

Browse files
author
Ben Sigelman
committed
Automated commit
1 parent 6f77b6f commit 1b93f76

File tree

11 files changed

+176
-167
lines changed

11 files changed

+176
-167
lines changed

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Resonance Labs, Inc
3+
Copyright (c) 2015-2016 LightStep
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22-

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pip install lightstep
1414

1515
## Getting Started
1616

17-
Please see the [example programs](examples/) for examples of how to use this library.
18-
In particular:
17+
Please see the [example programs](examples/) for examples of how to use this library. In particular:
18+
1919
* [Trivial Example](examples/trivial/main.py) shows how to use the library on a single host.
2020
* [Context in Headers](examples/http/context_in_headers.py) shows how to pass a `TraceContext` through `HTTP` headers.
2121

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.1
1+
2.0.2

examples/http/context_in_headers.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ def before_sending_request(request, parent_span):
4545
if host:
4646
span.set_tag(opentracing.ext.tags.PEER_HOST_IPV4, host)
4747

48-
text_carrier = opentracing.SplitTextCarrier()
49-
span.tracer.injector(opentracing.Format.SPLIT_TEXT).inject_span(
50-
span, text_carrier)
51-
for k, v in text_carrier.tracer_state.iteritems():
52-
request.add_header(k, v)
53-
for k, v in text_carrier.baggage.iteritems():
48+
text_carrier = {}
49+
span.tracer.inject(span, opentracing.Format.TEXT_MAP, text_carrier)
50+
for k, v in text_carrier.iteritems():
5451
request.add_header(k, v)
5552
return span
5653

@@ -59,23 +56,19 @@ def before_answering_request(handler, tracer):
5956
"""Context manager creates a Span, using TraceContext encoded in handler if possible.
6057
"""
6158
operation = 'handle_request:' + handler.path
62-
text_carrier = opentracing.SplitTextCarrier()
63-
plain_text_map = {}
59+
text_carrier = {}
6460
for k, v in handler.headers.items():
65-
plain_text_map[k.lower()] = v # inefficient and possibly unnecessary...
66-
text_carrier.tracer_state = plain_text_map
67-
text_carrier.baggage = plain_text_map
68-
span = tracer.extractor(opentracing.Format.SPLIT_TEXT).join_trace(
69-
operation, text_carrier)
61+
text_carrier[k] = v
62+
span = tracer.join(operation, opentracing.Format.TEXT_MAP, text_carrier)
7063

7164
if span is None:
7265
print 'ERROR: Context missing, starting new trace'
7366
global _exit_code
7467
_exit_code = errno.ENOMSG
7568
span = tracer.start_span(operation_name=operation)
7669
headers = ', '.join({k + '=' + v for k, v in handler.headers.items()})
77-
span.log_event('extraction_failed', headers)
78-
print 'Could not extract trace context from http headers: ' + headers
70+
span.log_event('join_failed', headers)
71+
print 'Could not join trace from http headers: ' + headers
7972

8073
host, port = handler.client_address
8174
if host:

examples/trivial/main.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ def add_spans():
3333
child_span.set_tag('span_type', 'child')
3434
sleep_dot()
3535

36-
# To connect remote calls, pass a trace context down the wire.
37-
split_text_carrier = opentracing.SplitTextCarrier()
38-
opentracing.tracer.injector(opentracing.Format.SPLIT_TEXT).inject_span(
39-
child_span, split_text_carrier)
40-
with opentracing.tracer.extractor(opentracing.Format.SPLIT_TEXT).join_trace(
41-
'trivial/remote_span', split_text_carrier) as remote_span:
36+
# Play with the propagation APIs... this is not IPC and thus not
37+
# where they're intended to be used.
38+
text_carrier = {}
39+
opentracing.tracer.inject(child_span, opentracing.Format.TEXT_MAP, text_carrier)
40+
with opentracing.tracer.join(
41+
'trivia/remote_span',
42+
opentracing.Format.TEXT_MAP,
43+
text_carrier) as remote_span:
4244
remote_span.log_event('Remote!')
4345
remote_span.set_tag('span_type', 'remote')
4446
sleep_dot()
@@ -80,10 +82,7 @@ def lightstep_tracer_from_args():
8082

8183
# Use opentracing's default no-op implementation
8284
opentracing.tracer = opentracing.Tracer()
83-
try:
84-
add_spans()
85-
finally:
86-
opentracing.tracer.flush()
85+
add_spans()
8786

8887
# Use LightStep's debug tracer, which logs to the console instead of
8988
# reporting to LightStep.

lightstep/crouton/ttypes.py

Lines changed: 61 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lightstep/instrument.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def __init__(self,
4242
max_span_records=constants.DEFAULT_MAX_SPAN_RECORDS,
4343
certificate_verification=True,
4444
periodic_flush_seconds=constants.FLUSH_PERIOD_SECS):
45+
46+
# Fail fast on a bad access token
47+
if isinstance(access_token, basestring) == False:
48+
raise Exception('access_token must be a string')
49+
4550
if certificate_verification is False:
4651
warnings.warn('SSL CERTIFICATE VERIFICATION turned off. ALL FUTURE HTTPS calls will be unverified.')
4752
ssl._create_default_https_context = ssl._create_unverified_context
@@ -56,7 +61,9 @@ def __init__(self,
5661
ttypes.KeyValue("cruntime_version", cruntime_version.CRUNTIME_VERSION),
5762
ttypes.KeyValue("python_version", version),
5863
]
59-
self._runtime = ttypes.Runtime(guid, timestamp, group_name, attrs)
64+
65+
# Thrift is picky about the types being correct, so we're explicit here
66+
self._runtime = ttypes.Runtime(str(guid), long(timestamp), str(group_name), attrs)
6067
self._service_url = util._service_url_from_hostport(secure,
6168
service_host,
6269
service_port)

0 commit comments

Comments
 (0)