opencensus-python icon indicating copy to clipboard operation
opencensus-python copied to clipboard

Allow to configure the cloud role parameter

Open se02035 opened this issue 4 years ago • 4 comments

It is unclear how to set the cloud role value for a log record. According to https://github.com/census-instrumentation/opencensus-python/blob/5ad2a7cc62fc9663d186e15636a7b0306c9a8d7a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/utils.py#L27 the cloud is always 'ai.cloud.role': os.path.basename(sys.argv[0]) or 'Python Application' This is a problem when multiple applications send traces to a single AppInsights instance (and have the same entry point e.g. main.py)

A correct cloud role name is essential for Azure Application Insights Application Map. In order to use another role name (which is likely true for most of the cases) a custom callback has be used to update the role name. It would be better to have an parameter on "Options" https://github.com/census-instrumentation/opencensus-python/blob/1ca601584cbbd3b6019bddb9c7120c069ff4f819/contrib/opencensus-ext-azure/opencensus/ext/azure/common/init.py#L104 to set the cloud role (and instance) and pass use that value when creating the log/trace records - similar to the instrumentation key/connection string.

se02035 avatar Jul 19 '21 14:07 se02035

You can modify this field via telemetry processors

lzchen avatar Jul 19 '21 16:07 lzchen

Yeah, I know but wouldn't it be nicer/cleaner to have a env var here? I mean I see a couple of benefits:

  1. other AI SDKs also allow to set the cloud role name via an env var.
  2. Similar approach is used for passing the AI instrumentation key
  3. the telemetry processor has to be configured for every AzureExporter/AzureLogHandler instance. E..g you need to do something like this (when using Azure Functions):
    • OpenCensusExtension._exporter.add_telemetry_processor(..) plus use the same for other AzureLogHandler (if available).

se02035 avatar Aug 09 '21 13:08 se02035

@se02035

Those are excellent points and I agree with it. Feel free to open a PR and I will review it :)

lzchen avatar Aug 10 '21 17:08 lzchen

@lzchen , created a PR for allowing devs to set the cloud role name via an envvar. pls see https://github.com/census-instrumentation/opencensus-python/pull/1061

se02035 avatar Aug 11 '21 15:08 se02035