Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f05fa77

Browse files
authored
Rename instrumentation examples (open-telemetry#3206)
1 parent d2edb40 commit f05fa77

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

docs/examples/auto-instrumentation/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Auto-instrumentation
44
To learn about automatic instrumentation and how to run the example in this
55
directory, see `Automatic Instrumentation`_.
66

7-
.. _Automatic Instrumentation: https://opentelemetry.io/docs/instrumentation/python/automatic/
7+
.. _Automatic Instrumentation: https://opentelemetry.io/docs/instrumentation/python/automatic/example

docs/examples/auto-instrumentation/server_instrumented.py renamed to docs/examples/auto-instrumentation/server_manual.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,25 @@
1414

1515
from flask import Flask, request
1616

17-
from opentelemetry import trace
1817
from opentelemetry.instrumentation.wsgi import collect_request_attributes
1918
from opentelemetry.propagate import extract
2019
from opentelemetry.sdk.trace import TracerProvider
2120
from opentelemetry.sdk.trace.export import (
2221
BatchSpanProcessor,
2322
ConsoleSpanExporter,
2423
)
24+
from opentelemetry.trace import (
25+
SpanKind,
26+
get_tracer_provider,
27+
set_tracer_provider,
28+
)
2529

2630
app = Flask(__name__)
2731

28-
trace.set_tracer_provider(TracerProvider())
29-
tracer = trace.get_tracer_provider().get_tracer(__name__)
32+
set_tracer_provider(TracerProvider())
33+
tracer = get_tracer_provider().get_tracer(__name__)
3034

31-
trace.get_tracer_provider().add_span_processor(
35+
get_tracer_provider().add_span_processor(
3236
BatchSpanProcessor(ConsoleSpanExporter())
3337
)
3438

@@ -38,7 +42,7 @@ def server_request():
3842
with tracer.start_as_current_span(
3943
"server_request",
4044
context=extract(request.headers),
41-
kind=trace.SpanKind.SERVER,
45+
kind=SpanKind.SERVER,
4246
attributes=collect_request_attributes(request.environ),
4347
):
4448
print(request.args.get("param"))
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
from flask import Flask, request
16+
17+
from opentelemetry.instrumentation.flask import FlaskInstrumentor
18+
from opentelemetry.sdk.trace import TracerProvider
19+
from opentelemetry.sdk.trace.export import (
20+
BatchSpanProcessor,
21+
ConsoleSpanExporter,
22+
)
23+
from opentelemetry.trace import get_tracer_provider, set_tracer_provider
24+
25+
set_tracer_provider(TracerProvider())
26+
get_tracer_provider().add_span_processor(
27+
BatchSpanProcessor(ConsoleSpanExporter())
28+
)
29+
30+
instrumentor = FlaskInstrumentor()
31+
32+
app = Flask(__name__)
33+
34+
instrumentor.instrument_app(app)
35+
# instrumentor.instrument_app(app, excluded_urls="/server_request")
36+
37+
38+
@app.route("/server_request")
39+
def server_request():
40+
print(request.args.get("param"))
41+
return "served"
42+
43+
44+
if __name__ == "__main__":
45+
app.run(port=8082)

0 commit comments

Comments
 (0)