-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Implement live metrics filtering for charts (part 1) #37998
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 1 commit
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3209a6e
qp
lzchen 691ea15
update config
lzchen 59cb90d
telemetry type
lzchen 57be629
init dervied metrics
lzchen bf0a70d
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
lzchen 3868560
target
lzchen 569ca90
filtering + start of projections
lzchen 0d1e46a
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
lzchen 055b8be
collection + exporting
lzchen 09b1b8f
tests
lzchen 2afed98
exporter tests
lzchen 2845946
test live metrics
lzchen 1eefc4a
trace utils
lzchen 0da3860
derive
lzchen cba3518
filters
lzchen bea3637
projections
lzchen be7859c
live
lzchen 3a1523c
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
lzchen e87cb8b
Update _exporter.py
lzchen 4ecc2d0
lint
lzchen fb5dbc8
black
lzchen ca864d8
lint
lzchen 236f6f3
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
lzchen f0ccd8b
lint
lzchen 10df783
blac
lzchen d12aec6
comment
lzchen 179c24d
Update test_utils.py
lzchen dc0d0a0
Update test_live_metrics.py
lzchen 8de5913
comment
lzchen b8fb7cb
test
lzchen 6c6da94
tests
lzchen 979096a
lint
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
filtering + start of projections
- Loading branch information
commit 569ca900efee818e3768aadee7614025a8bbc38c
There are no files selected for viewing
80 changes: 0 additions & 80 deletions
80
...onitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_quickpulse/_filter.py
This file was deleted.
Oops, something went wrong.
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
173 changes: 173 additions & 0 deletions
173
...monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_quickpulse/_types.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,173 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| from dataclasses import dataclass | ||
| from typing import Dict | ||
|
|
||
| from opentelemetry.sdk._logs import LogRecord | ||
| from opentelemetry.sdk.trace import ReadableSpan | ||
| from opentelemetry.semconv.trace import SpanAttributes | ||
| from opentelemetry.trace import SpanKind | ||
| from opentelemetry.util.types import Attributes | ||
|
|
||
| from azure.monitor.opentelemetry.exporter.export.trace import _utils as trace_utils | ||
|
|
||
| @dataclass | ||
| class _TelemetryData: | ||
| custom_dimensions: Dict[str, str] | ||
|
|
||
| @staticmethod | ||
| def _from_span(span: ReadableSpan): | ||
| if span.kind in (SpanKind.SERVER, SpanKind.CONSUMER): | ||
| return _RequestData._from_span(span) | ||
| else: | ||
| return _DependencyData._from_span(span) | ||
|
|
||
| @staticmethod | ||
| def _from_log_record(log_record: LogRecord): | ||
| exc_type = log_data.log_record.attributes.get(SpanAttributes.EXCEPTION_TYPE) # type: ignore | ||
| exc_message = log_data.log_record.attributes.get(SpanAttributes.EXCEPTION_MESSAGE) # type: ignore | ||
| if exc_type is not None or exc_message is not None: | ||
| return _ExceptionData._from_log_record(log_record) | ||
| else: | ||
| return _TraceData._from_log_record(log_record) | ||
|
|
||
|
|
||
| @dataclass | ||
| class _RequestData(_TelemetryData): | ||
| duration: float | ||
| success: bool | ||
| name: str | ||
| response_code: int | ||
| url: str | ||
|
|
||
| @staticmethod | ||
| def _from_span(span: ReadableSpan): | ||
| # Logic should match that of exporter to Breeze | ||
| url = "" | ||
| duration_ms = 0 | ||
| response_code = 0 | ||
| success = True | ||
| attributes = {} | ||
| if span.end_time and span.start_time: | ||
| duration_ms = (span.end_time - span.start_time) / 1e9 # type: ignore | ||
| if span.attributes: | ||
| attributes = span.attributes | ||
| url = span.attributes.get(SpanAttributes.HTTP_URL, "") | ||
| status_code = span.attributes.get(SpanAttributes.HTTP_STATUS_CODE) | ||
| if status_code: | ||
| try: | ||
| status_code = int(status_code) # type: ignore | ||
| except ValueError: | ||
| status_code = 0 | ||
| else: | ||
| status_code = 0 | ||
| success = span.status.is_ok and status_code and status_code not in range(400, 500) | ||
harsimar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| response_code = status_code | ||
| return _RequestData( | ||
| duration=duration_ms, | ||
| success=success, | ||
| name=span.name, | ||
| response_code=response_code, | ||
| url=str(url), | ||
| custom_dimensions=attributes, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class _DependencyData(_TelemetryData): | ||
| duration: float | ||
| success: bool | ||
| name: str | ||
| result_code: int | ||
| target: str | ||
| type: str | ||
| data: str | ||
|
|
||
| @staticmethod | ||
| def _from_span(span: ReadableSpan): | ||
harsimar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Logic should match that of exporter to Breeze | ||
| url = "" | ||
| duration_ms = 0 | ||
| result_code = 0 | ||
| attributes = {} | ||
| dependency_type = "" | ||
| data = "" | ||
| target = trace_utils._get_target_for_dependency_from_peer(span.attributes) | ||
| if SpanAttributes.HTTP_METHOD in span.attributes: | ||
| dependency_type = "HTTP" | ||
| scheme = trace_utils._get_scheme_for_http_dependency(span.attributes) | ||
| url = trace_utils._get_url_for_http_dependency(scheme, span.attributes) | ||
| target, _ = trace_utils._get_target_and_path_for_http_dependency( | ||
| target, | ||
| url, | ||
| scheme, | ||
| span.attributes, | ||
| ) | ||
| data = url | ||
| elif SpanAttributes.DB_SYSTEM in span.attributes: | ||
| db_system = span.attributes[SpanAttributes.DB_SYSTEM] | ||
| dependency_type = db_system | ||
| target = trace_utils._get_target_for_db_dependency( | ||
| target, # type: ignore | ||
| db_system, # type: ignore | ||
| span.attributes, | ||
| ) | ||
| if SpanAttributes.DB_STATEMENT in span.attributes: | ||
| data = span.attributes[SpanAttributes.DB_STATEMENT] | ||
| elif SpanAttributes.DB_OPERATION in span.attributes: | ||
| data = span.attributes[SpanAttributes.DB_OPERATION] | ||
| elif SpanAttributes.MESSAGING_SYSTEM in span.attributes: | ||
| dependency_type = span.attributes[SpanAttributes.MESSAGING_SYSTEM] | ||
| target = trace_utils._get_target_for_messaging_dependency( | ||
| target, # type: ignore | ||
| span.attributes, | ||
| ) | ||
| elif SpanAttributes.RPC_SYSTEM in span.attributes: | ||
| dependency_type = span.attributes[SpanAttributes.RPC_SYSTEM] | ||
| target = trace_utils._get_target_for_rpc_dependency( | ||
| target, # type: ignore | ||
| span.attributes, | ||
| ) | ||
| elif span.kind is SpanKind.PRODUCER: | ||
| dependency_type = "Queue Message" | ||
| msg_system = span.attributes.get(SpanAttributes.MESSAGING_SYSTEM) | ||
| if msg_system: | ||
| dependency_type += " | {}".format(msg_system) | ||
| else: | ||
| dependency_type = "InProc" | ||
|
|
||
| return _DependencyData( | ||
| duration=duration_ms, | ||
| success=span.status.is_ok, | ||
| name=span.name, | ||
| result_code=result_code, | ||
| target=target, | ||
| type=str(dependency_type), | ||
| data=data, | ||
| custom_dimensions=attributes, | ||
| ) | ||
|
|
||
| @dataclass | ||
| class _ExceptionData(_TelemetryData): | ||
| message: str | ||
| stack_trace: str | ||
|
|
||
| @staticmethod | ||
| def _from_log_record(log_record: LogRecord): | ||
| return _ExceptionData( | ||
| message=str(log_record.attributes.get(SpanAttributes.EXCEPTION_MESSAGE, "")), | ||
| stack_trace=str(log_record.attributes.get(SpanAttributes.EXCEPTION_STACKTRACE, "")), | ||
| custom_dimensions=log_record.attributes, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class _TraceData(_TelemetryData): | ||
| message: str | ||
|
|
||
| @staticmethod | ||
| def _TraceData(log_record: LogRecord): | ||
| return _TraceData( | ||
| message=str(log_record.body), | ||
| custom_dimensions=log_record.attributes, | ||
| ) | ||
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.