-
Notifications
You must be signed in to change notification settings - Fork 250
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
Implement custom events in Azure #925
Conversation
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.
LGTM! I noticed a lot of this is just refactoring, so it's understandable if you don't wanna tweak old code I nit'ed
def _export(self, batch, event=None): # pragma: NO COVER | ||
try: | ||
if batch: | ||
envelopes = [self.log_record_to_envelope(x) for x in batch] |
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.
If apply_telemetry_processors()
just needs an iterable, could use generator
envelopes = [self.log_record_to_envelope(x) for x in batch] | |
envelopes = (self.log_record_to_envelope(x) for x in batch) |
envelope.tags['ai.operation.id'] = getattr( | ||
record, | ||
'traceId', | ||
'00000000000000000000000000000000', |
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.
'0' * n
?
) | ||
envelope.tags['ai.operation.parentId'] = '|{}.{}.'.format( | ||
envelope.tags['ai.operation.id'], | ||
getattr(record, 'spanId', '0000000000000000'), |
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.
same
from opencensus.ext.azure.common import Options | ||
instrumentation_key = Options._default.instrumentation_key | ||
Options._default.instrumentation_key = None | ||
self.assertRaises(ValueError, lambda: log_exporter.AzureEventHandler()) |
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.
nit don't need the lambda
here
'key_1': 'value_1', | ||
'key_2': 'value_2' |
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.
nit indent
logger = logging.getLogger(self.id()) | ||
handler = log_exporter.AzureEventHandler( | ||
instrumentation_key='12345678-1234-5678-abcd-12345678abcd', | ||
logging_sampling_rate=0.0, | ||
) | ||
logger.addHandler(handler) |
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.
nit could stick this in a contextmanager since it appears a few times and (I guess) you need to remember handler.close()
Send
customEvent
telemetry to Azure in exactly the same way astrace
telemetry but using a different log handler instead (AzureEventHandler
). We usually will recommend customers to use two separate loggers in this case if they want bothtrace
andcustomEvent
.