Skip to content
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

Merged
merged 5 commits into from
Jun 29, 2020
Merged

Conversation

lzchen
Copy link
Contributor

@lzchen lzchen commented Jun 28, 2020

Send customEvent telemetry to Azure in exactly the same way as trace 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 both trace and customEvent.

Copy link
Member

@aabmass aabmass left a 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]
Copy link
Member

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

Suggested change
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',
Copy link
Member

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'),
Copy link
Member

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())
Copy link
Member

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

Comment on lines +323 to +324
'key_1': 'value_1',
'key_2': 'value_2'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit indent

Comment on lines +443 to +448
logger = logging.getLogger(self.id())
handler = log_exporter.AzureEventHandler(
instrumentation_key='12345678-1234-5678-abcd-12345678abcd',
logging_sampling_rate=0.0,
)
logger.addHandler(handler)
Copy link
Member

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()

@lzchen lzchen merged commit dea0794 into census-instrumentation:master Jun 29, 2020
@lzchen lzchen deleted the events branch June 29, 2020 18:43
@lzchen lzchen mentioned this pull request Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants