Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Implement custom events in Azure#925

Merged
lzchen merged 5 commits intocensus-instrumentation:masterfrom
lzchen:events
Jun 29, 2020
Merged

Implement custom events in Azure#925
lzchen merged 5 commits intocensus-instrumentation:masterfrom
lzchen:events

Conversation

@lzchen
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants