This repository was archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Adding live metrics #96
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
02c3bd1
Adding live metrics
hectorhdzg e90e569
Merge branch 'master' into hectorh/liveMetr
hectorhdzg 5173e55
Fixing lint issues
hectorhdzg 52a293e
Merge branch 'hectorh/liveMetr' of https://github.com/hectorhdzg/open…
hectorhdzg db4914c
Using single classes for live/standard metrics to avoid duplication
hectorhdzg c18bf17
Adding tests
hectorhdzg fc4a642
Lint
hectorhdzg 0c23ccc
Fixing issue with rates as int
hectorhdzg 0a5a2e2
Fixing issue with documents parsing
hectorhdzg 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
from azure_monitor.export import ( | ||
BaseExporter, | ||
ExportResult, | ||
convert_span_to_envelope, | ||
get_trace_export_result, | ||
) | ||
|
||
|
@@ -52,104 +53,6 @@ def export(self, spans: Sequence[Span]) -> SpanExportResult: | |
def _span_to_envelope(self, span: Span) -> protocol.Envelope: | ||
if not span: | ||
return None | ||
envelope = protocol.Envelope( | ||
ikey=self.options.instrumentation_key, | ||
tags=dict(utils.azure_monitor_context), | ||
time=ns_to_iso_str(span.start_time), | ||
) | ||
envelope.tags["ai.operation.id"] = "{:032x}".format( | ||
span.context.trace_id | ||
) | ||
parent = span.parent | ||
if isinstance(parent, Span): | ||
parent = parent.context | ||
if parent: | ||
envelope.tags["ai.operation.parentId"] = "{:016x}".format( | ||
parent.span_id | ||
) | ||
if span.kind in (SpanKind.CONSUMER, SpanKind.SERVER): | ||
envelope.name = "Microsoft.ApplicationInsights.Request" | ||
data = protocol.Request( | ||
id="{:016x}".format(span.context.span_id), | ||
duration=utils.ns_to_duration(span.end_time - span.start_time), | ||
response_code=str(span.status.canonical_code.value), | ||
success=span.status.canonical_code | ||
== StatusCanonicalCode.OK, # Modify based off attributes or Status | ||
properties={}, | ||
) | ||
envelope.data = protocol.Data( | ||
base_data=data, base_type="RequestData" | ||
) | ||
if "http.method" in span.attributes: | ||
data.name = span.attributes["http.method"] | ||
if "http.route" in span.attributes: | ||
data.name = data.name + " " + span.attributes["http.route"] | ||
envelope.tags["ai.operation.name"] = data.name | ||
data.properties["request.name"] = data.name | ||
elif "http.path" in span.attributes: | ||
data.properties["request.name"] = ( | ||
data.name + " " + span.attributes["http.path"] | ||
) | ||
if "http.url" in span.attributes: | ||
data.url = span.attributes["http.url"] | ||
data.properties["request.url"] = span.attributes["http.url"] | ||
if "http.status_code" in span.attributes: | ||
status_code = span.attributes["http.status_code"] | ||
data.response_code = str(status_code) | ||
data.success = 200 <= status_code < 400 | ||
else: | ||
envelope.name = "Microsoft.ApplicationInsights.RemoteDependency" | ||
data = protocol.RemoteDependency( | ||
name=span.name, | ||
id="{:016x}".format(span.context.span_id), | ||
result_code=str(span.status.canonical_code.value), | ||
duration=utils.ns_to_duration(span.end_time - span.start_time), | ||
success=span.status.canonical_code | ||
== StatusCanonicalCode.OK, # Modify based off attributes or Status | ||
properties={}, | ||
) | ||
envelope.data = protocol.Data( | ||
base_data=data, base_type="RemoteDependencyData" | ||
) | ||
if span.kind in (SpanKind.CLIENT, SpanKind.PRODUCER): | ||
if ( | ||
"component" in span.attributes | ||
and span.attributes["component"] == "http" | ||
): | ||
data.type = "HTTP" | ||
if "http.url" in span.attributes: | ||
url = span.attributes["http.url"] | ||
# data is the url | ||
data.data = url | ||
parse_url = urlparse(url) | ||
# TODO: error handling, probably put scheme as well | ||
# target matches authority (host:port) | ||
data.target = parse_url.netloc | ||
if "http.method" in span.attributes: | ||
# name is METHOD/path | ||
data.name = ( | ||
span.attributes["http.method"] | ||
+ "/" | ||
+ parse_url.path | ||
) | ||
if "http.status_code" in span.attributes: | ||
status_code = span.attributes["http.status_code"] | ||
data.result_code = str(status_code) | ||
data.success = 200 <= status_code < 400 | ||
else: # SpanKind.INTERNAL | ||
data.type = "InProc" | ||
data.success = True | ||
for key in span.attributes: | ||
# This removes redundant data from ApplicationInsights | ||
if key.startswith("http."): | ||
continue | ||
data.properties[key] = span.attributes[key] | ||
if span.links: | ||
links = [] | ||
for link in span.links: | ||
operation_id = "{:032x}".format(link.context.trace_id) | ||
span_id = "{:016x}".format(link.context.span_id) | ||
links.append({"operation_Id": operation_id, "id": span_id}) | ||
data.properties["_MS.links"] = json.dumps(links) | ||
# TODO: tracestate, tags | ||
envelope = convert_span_to_envelope(span) | ||
envelope.ikey = self.options.instrumentation_key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come we can't set the ikey in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ikey is not available everywhere in the SDK, is currently specific to exporters, validation code is already in there, will need to centralize ikey management to be able to add the ikey in some shared function |
||
return envelope |
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
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.
Why move this here?
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.
Need this conversion in LiveMetrics processing, could move to a more appropriate location like utility or something, any suggestion?
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.
Can we leave this in trace and have LiveMetrics just import from trace module?