-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Add support for OTLP exported metrics and tracing #1489
Open
tonybaloney
wants to merge
15
commits into
Azure-Samples:main
Choose a base branch
from
tonybaloney:otel_grpc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+175
−45
Open
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6a6f489
Set public network access to deny and allow azure network access by d…
tonybaloney 39ee118
OLTP sandbox
tonybaloney 2097e98
OTLP with GRPC and custom metrics
tonybaloney f6a22bb
Tidy up experiments
tonybaloney dfc61d7
Merge branch 'main' into otel_grpc
tonybaloney 950279a
Add logging support
tonybaloney 0d492a9
Merge branch 'otel_grpc' of github.com:tonybaloney/azure-search-opena…
tonybaloney 5d2a34b
Clean up and formatting
tonybaloney 0804dd9
Add docs on OTEL, sort imports
tonybaloney 1d61425
Update default args for OTLP configuration
tonybaloney 70fa2ef
Reformat using new black
tonybaloney 9319a6e
Link documents
tonybaloney caac590
Don't use metrics for now
tonybaloney 0661f48
rollback keyvault changes
tonybaloney 0ee02a0
Fix markdown reference
tonybaloney 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 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 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 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,51 @@ | ||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource | ||
|
||
from opentelemetry import trace | ||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter as OTLPHTTPSpanExporter | ||
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter as OTLPGRPCSpanExporter | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import BatchSpanProcessor | ||
|
||
from opentelemetry import metrics | ||
from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter as OTLPHTTPMetricExporter | ||
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter as OTLPGRPCMetricExporter | ||
from opentelemetry.sdk.metrics import MeterProvider | ||
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader | ||
|
||
|
||
def configure_oltp_http_tracing(service_name: str = "azure-search-openai-demo", endpoint: str = "http://localhost:4318"): | ||
# Service name is required for most backends | ||
resource = Resource(attributes={ | ||
SERVICE_NAME: service_name | ||
}) | ||
|
||
traceProvider = TracerProvider(resource=resource) | ||
# Trick OLTP into thinking the httpx client is a requests session so that HTTP2 works | ||
processor = BatchSpanProcessor(OTLPHTTPSpanExporter(endpoint=f"{endpoint}/v1/traces",)) | ||
traceProvider.add_span_processor(processor) | ||
trace.set_tracer_provider(traceProvider) | ||
|
||
reader = PeriodicExportingMetricReader( | ||
OTLPHTTPMetricExporter(endpoint=f"{endpoint}/v1/metrics") | ||
) | ||
meterProvider = MeterProvider(resource=resource, metric_readers=[reader]) | ||
metrics.set_meter_provider(meterProvider) | ||
|
||
|
||
def configure_oltp_grpc_tracing(service_name: str = "azure-search-openai-demo", endpoint: str = "http://localhost:4317"): | ||
# Service name is required for most backends | ||
resource = Resource(attributes={ | ||
SERVICE_NAME: service_name | ||
}) | ||
|
||
traceProvider = TracerProvider(resource=resource) | ||
# Trick OLTP into thinking the httpx client is a requests session so that HTTP2 works | ||
processor = BatchSpanProcessor(OTLPGRPCSpanExporter(endpoint=endpoint, insecure=True)) | ||
traceProvider.add_span_processor(processor) | ||
trace.set_tracer_provider(traceProvider) | ||
|
||
reader = PeriodicExportingMetricReader( | ||
OTLPGRPCMetricExporter(endpoint=endpoint, insecure=True) | ||
) | ||
meterProvider = MeterProvider(resource=resource, metric_readers=[reader]) | ||
metrics.set_meter_provider(meterProvider) |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this for non-Azure Monitor endpoint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it'll work with all the other vendors