-
Notifications
You must be signed in to change notification settings - Fork 78
Add instrumentation selection configuration #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
aa4ec47
instr
lzchen 6465382
Merge branch 'main' of https://github.com/microsoft/ApplicationInsigh…
lzchen 10d10fe
Merge branch 'main' of https://github.com/microsoft/ApplicationInsigh…
lzchen 0596c09
instr
lzchen 241ba2d
lint
lzchen 2f4de3e
Update .flake8
lzchen 5e498cf
Update .flake8
lzchen 5c32d63
Update db_psycopg2.py
lzchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ exclude = | |
| CVS | ||
| .venv*/ | ||
| venv*/ | ||
| */samples/* | ||
| target | ||
| __pycache__ | ||
| */build/lib/* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
azure-monitor-opentelemetry-distro/samples/tracing/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| import logging | ||
|
|
||
| import requests | ||
| from azure.monitor.opentelemetry.distro import configure_azure_monitor | ||
| from opentelemetry import trace | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| # Configure Azure monitor collection telemetry pipeline | ||
| configure_azure_monitor( | ||
| connection_string="<your-connection-string>", | ||
| service_name="client_service_name", | ||
| disable_logging=True, | ||
| instrumentations=["requests"], | ||
| tracing_export_interval_millis=15000, | ||
| ) | ||
|
|
||
| tracer = trace.get_tracer(__name__) | ||
| with tracer.start_as_current_span("Request parent span") as span: | ||
| try: | ||
| # Requests made using the requests library will be automatically captured | ||
| response = requests.get("https://azure.microsoft.com/", timeout=5) | ||
| logger.warning("Request sent") | ||
| except Exception as ex: | ||
| # If an exception occurs, this can be manually recorded on the parent span | ||
| span.set_attribute("status", "exception") | ||
| span.record_exception(ex) | ||
|
|
||
| input() |
22 changes: 22 additions & 0 deletions
22
azure-monitor-opentelemetry-distro/samples/tracing/db_psycopg2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| import psycopg2 | ||
| from azure.monitor.opentelemetry.distro import configure_azure_monitor | ||
|
|
||
| # Configure Azure monitor collection telemetry pipeline | ||
| configure_azure_monitor( | ||
| connection_string="<your-connection-string>", | ||
| service_name="psycopg2_service_name", | ||
| disable_logging=True, | ||
| instrumentations=["psycopg2"], | ||
| tracing_export_interval_millis=15000, | ||
| ) | ||
|
|
||
| cnx = psycopg2.connect(database="test", user="<user>", password="<password>") | ||
| cursor = cnx.cursor() | ||
| cursor.execute("INSERT INTO test_tables (test_field) VALUES (123)") | ||
| cursor.close() | ||
| cnx.close() |
2 changes: 2 additions & 0 deletions
2
azure-monitor-opentelemetry-distro/samples/tracing/django/sample/example/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. |
5 changes: 5 additions & 0 deletions
5
azure-monitor-opentelemetry-distro/samples/tracing/django/sample/example/admin.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| from django.contrib import admin | ||
|
|
||
| # Register your models here. |
8 changes: 8 additions & 0 deletions
8
azure-monitor-opentelemetry-distro/samples/tracing/django/sample/example/apps.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class ExampleConfig(AppConfig): | ||
| default_auto_field = "django.db.models.BigAutoField" | ||
| name = "example" |
2 changes: 2 additions & 0 deletions
2
...monitor-opentelemetry-distro/samples/tracing/django/sample/example/migrations/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. |
5 changes: 5 additions & 0 deletions
5
azure-monitor-opentelemetry-distro/samples/tracing/django/sample/example/models.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| from django.db import models | ||
|
|
||
| # Create your models here. |
5 changes: 5 additions & 0 deletions
5
azure-monitor-opentelemetry-distro/samples/tracing/django/sample/example/tests.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| from django.test import TestCase | ||
|
|
||
| # Create your tests here. |
10 changes: 10 additions & 0 deletions
10
azure-monitor-opentelemetry-distro/samples/tracing/django/sample/example/urls.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| from django.urls import path | ||
|
|
||
| from . import views | ||
|
|
||
| urlpatterns = [ | ||
| path("", views.index, name="index"), | ||
| path("exception", views.exception, name="exception"), | ||
| ] |
26 changes: 26 additions & 0 deletions
26
azure-monitor-opentelemetry-distro/samples/tracing/django/sample/example/views.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
|
|
||
| from azure.monitor.opentelemetry.distro import configure_azure_monitor | ||
| from django.http import HttpResponse | ||
|
|
||
| # Configure Azure monitor collection telemetry pipeline | ||
| configure_azure_monitor( | ||
| # connection_string="<your-connection-string>", | ||
| service_name="django_service_name", | ||
| instrumentations=["django"], | ||
| disable_logging=True, | ||
| tracing_export_interval_millis=15000, | ||
| ) | ||
|
|
||
| # Requests sent to the django application will be automatically captured | ||
| def index(request): | ||
| return HttpResponse("Hello, world.") | ||
|
|
||
|
|
||
| # Exceptions that are raised within the request are automatically captured | ||
| def exception(request): | ||
| raise Exception("Exception was raised.") |
25 changes: 25 additions & 0 deletions
25
azure-monitor-opentelemetry-distro/samples/tracing/django/sample/manage.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| #!/usr/bin/env python | ||
| """Django's command-line utility for administrative tasks.""" | ||
| import os | ||
| import sys | ||
|
|
||
|
|
||
| def main(): | ||
| """Run administrative tasks.""" | ||
| os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample.settings") | ||
|
|
||
| try: | ||
| from django.core.management import execute_from_command_line | ||
| except ImportError as exc: | ||
| raise ImportError( | ||
| "Couldn't import Django. Are you sure it's installed and " | ||
| "available on your PYTHONPATH environment variable? Did you " | ||
| "forget to activate a virtual environment?" | ||
| ) from exc | ||
| execute_from_command_line(sys.argv) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
2 changes: 2 additions & 0 deletions
2
azure-monitor-opentelemetry-distro/samples/tracing/django/sample/sample/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.