Skip to content

Instantly share code, notes, and snippets.

@ocelotl
Created December 22, 2020 01:16
Show Gist options
  • Save ocelotl/10512d97f5beb041c90bfa2383f7b701 to your computer and use it in GitHub Desktop.
Save ocelotl/10512d97f5beb041c90bfa2383f7b701 to your computer and use it in GitHub Desktop.
Output
Traceback (most recent call last):
File "/home/ocelotl/.pyenv/versions/3.8.3/lib/python3.8/site-packages/scalene/scalene_profiler.py", line 1525, in main
exec(code, the_globals, the_locals)
File "opentelemetry-sdk/tests/performance/resource-usage/trace/test_resource_usage_simple_export.py", line 18, in <module>
from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter
File "/home/ocelotl/.pyenv/versions/3.8.3/lib/python3.8/site-packages/opentelemetry/exporter/otlp/trace_exporter/__init__.py", line 46, in <module>
from opentelemetry.sdk.trace import Span as SDKSpan
File "/home/ocelotl/.pyenv/versions/3.8.3/lib/python3.8/site-packages/opentelemetry/sdk/trace/__init__.py", line 45, in <module>
from opentelemetry.trace import SpanContext, sampling
ImportError: cannot import name 'sampling' from 'opentelemetry.trace' (/home/ocelotl/sandbox/test_entry_points/opentelemetry-api/src/opentelemetry/trace/__init__.py)
Memory usage: ▇▄▄▃▂▁▁▁▁▁▁▁▁▁▁▁▁▁▂▂▂▁▁ (max: 16.00MB)
opentelemetry-sdk/tests/performance/resource-usage/trace/test_resource_usage_simple_export.py: % of time = 100.00% out of 0.32s.
╷ ╷ ╷ ╷ ╷ ╷ ╷ ╷
Line │Time % │Time % │Sys │Mem % │Net │Memory usage │Copy │
│Python │native │% │Python │(MB) │over time / % │(MB/s) │opentelemetry-sdk/tests/performance/resource-usage/trace/test_resource_usage_simple_export.py
╺━━━━━━┿━━━━━━━┿━━━━━━━━┿━━━━┿━━━━━━━┿━━━━━━┿━━━━━━━━━━━━━━┿━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸
1 │ │ │ │ │ │ │ │# Copyright The OpenTelemetry Authors
2 │ │ │ │ │ │ │ │#
3 │ │ │ │ │ │ │ │# Licensed under the Apache License, Version 2.0 (the "License");
4 │ │ │ │ │ │ │ │# you may not use this file except in compliance with the License.
5 │ │ │ │ │ │ │ │# You may obtain a copy of the License at
6 │ │ │ │ │ │ │ │#
7 │ │ │ │ │ │ │ │# http://www.apache.org/licenses/LICENSE-2.0
8 │ │ │ │ │ │ │ │#
9 │ │ │ │ │ │ │ │# Unless required by applicable law or agreed to in writing, software
10 │ │ │ │ │ │ │ │# distributed under the License is distributed on an "AS IS" BASIS,
11 │ │ │ │ │ │ │ │# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 │ │ │ │ │ │ │ │# See the License for the specific language governing permissions and
13 │ │ │ │ │ │ │ │# limitations under the License.
14 │ │ │ │ │ │ │ │
15 │ │ │ │ │ │ │ │import time
16 │ 8% │ │ │ 100% │ 2 │▁▁▁▁ │ │from unittest import mock
16 │ 8% │ │ │ 100% │ 2 │▁▁▁▁ │ │from unittest import mock [2/216]
17 │ │ │ │ │ │ │ │
18 │ 91% │ 1% │ │ 95% │ -2 │▁▁▁▂▁▁▁ 87% │ 70 │from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter
19 │ │ │ │ │ │ │ │from opentelemetry.sdk.trace import TracerProvider, sampling
20 │ │ │ │ │ │ │ │from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor
21 │ │ │ │ │ │ │ │
22 │ │ │ │ │ │ │ │
23 │ │ │ │ │ │ │ │SPANS_PER_SECOND = 10_000
24 │ │ │ │ │ │ │ │
25 │ │ │ │ │ │ │ │simple_span_processor = SimpleExportSpanProcessor(OTLPSpanExporter())
26 │ │ │ │ │ │ │ │tracer = TracerProvider(
27 │ │ │ │ │ │ │ │ active_span_processor=simple_span_processor,
28 │ │ │ │ │ │ │ │ sampler=sampling.DEFAULT_ON,
29 │ │ │ │ │ │ │ │).get_tracer("resource_usage_tracer")
30 │ │ │ │ │ │ │ │
31 │ │ │ │ │ │ │ │
32 │ │ │ │ │ │ │ │class MockTraceServiceStub(object):
33 │ │ │ │ │ │ │ │ def __init__(self, channel):
34 │ │ │ │ │ │ │ │ self.Export = lambda *args, **kwargs: None
35 │ │ │ │ │ │ │ │
36 │ │ │ │ │ │ │ │
37 │ │ │ │ │ │ │ │def test_simple_span_processor():
38 │ │ │ │ │ │ │ │ patch = mock.patch(
39 │ │ │ │ │ │ │ │ "opentelemetry.exporter.otlp.trace_exporter.OTLPSpanExporter._stub",
40 │ │ │ │ │ │ │ │ new=MockTraceServiceStub,
41 │ │ │ │ │ │ │ │ )
42 │ │ │ │ │ │ │ │ with patch:
43 │ │ │ │ │ │ │ │ for i in range(15):
44 │ │ │ │ │ │ │ │ print("STARTING NUMBER: ", i)
45 │ │ │ │ │ │ │ │ starttime = time.time()
46 │ │ │ │ │ │ │ │ while time.time() - starttime < 60:
47 │ │ │ │ │ │ │ │ print("Difference is: ", time.time() - starttime)
48 │ │ │ │ │ │ │ │ span = tracer.start_span("benchmarkedSpan")
49 │ │ │ │ │ │ │ │ print("Do span work")
50 │ │ │ │ │ │ │ │ span.end()
51 │ │ │ │ │ │ │ │ print("Finish span work")
52 │ │ │ │ │ │ │ │ time.sleep(60.0 - ((time.time() - starttime) % 60.0))
53 │ │ │ │ │ │ │ │
54 │ │ │ │ │ │ │ │test_simple_span_processor()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment