question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CustomDimension not working

See original GitHub issue

Describe your environment. Version: python3.6 Running as a container in RHEL VM. After importing opencensus.ext.azure.log_exporter docker image is built only when the Dockerfile is changed to have RUN yum install -y gcc rh-python36 rh-python36-python-devel.x86_64

Steps to reproduce. logger.py

import logging
import os
from opencensus.ext.azure.log_exporter import AzureLogHandler

_azhandler = AzureLogHandler(connection_string='InstrumentationKey={}'.format(os.getenv('app_insights_instrumentation_key')))
_azhandler.setLevel(logging.DEBUG)
_azhandler.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
_azlogger = logging.getLogger('FileUploader')
_azlogger.addHandler(_azhandler)

def info_customdimension(message, customDictionary):
    try:
        _azlogger.info(message, extra=customDictionary)
        print('Sent custom dictionary log')
    except Exception:
        print('Cannot send custom dictionary log')

Consumer of this logger file

 custom_dimensions = {}
 custom_dimensions['JobId'] = job_id
 custom_dimensions['FileUpload'] = True
 custom_properties = {}
 custom_properties['custom_dimensions'] = custom_dimensions

 info_customdimension("Successfully uploaded'), custom_properties)

What is the expected behavior? Application insights log should show custom dimensions properties along with the log message.

What is the actual behavior? Application insights log shows only log message.

Additional context. Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
raphaelauvcommented, Feb 19, 2021

@Izchen alright ! thank you.

I will open a ticket when I can from my admins … ( You don’t have permission to create a support request … )

1reaction
raphaelauvcommented, Feb 19, 2021

I’m having the same problem with custom_metric -> https://github.com/census-instrumentation/opencensus-python/pull/820

the dimensions do not show up in azure monitor.

code to reproduce :

from opencensus.ext.azure.common import utils
from opencensus.ext.azure.common.protocol import Data, Envelope, MetricData
from opencensus.ext.azure.log_exporter import AzureLogHandler


class AzureMetricPublisher(AzureLogHandler):

    def track_metric(self, metric_name, metric_value, namespace=None, dimensions=None):
        if namespace is None:
            namespace = metric_name
        if dimensions is None:
            dimensions = {}
        self._queue.put((metric_name, metric_value, namespace, dimensions), block=False)

    def log_record_to_envelope(self, record):
        if isinstance(record, tuple):
            envelope = Envelope(
                iKey=self.options.instrumentation_key,
                tags=dict(utils.azure_monitor_context),
                time=utils.to_iso_str(),
            )
            envelope.name = 'Microsoft.ApplicationInsights.Metric'
            name = record[0]
            value = record[1]
            ns = record[2]
            dimensions = record[3]
            data = MetricData(
                metrics=[
                    {'kind': None,
                     'name': name,
                     'ns': ns,
                     'max': value,
                     'count': 1,
                     'value': value,
                     'min': value,
                     'stdDev': 0}],
                properties=dimensions
            )
            print(data)
            print("properties :" + str(data.properties))
            envelope.data = Data(baseData=data, baseType='MetricData')
            return envelope

        return super().log_record_to_envelope(record)


metric_exporter = AzureMetricPublisher(connection_string="KEY")

metric_exporter.track_metric(metric_name='test_metric',
                             metric_value=42,
                             namespace="test_domain",
                             dimensions={"test_dimension": "value_dimension"})

If you run this code @lzchen do you see the dimension in azure monitor ?

Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Analytics Custom Dimension Not Being Set
A dimension is sent along with the either a page view or an event. It won't get sent by itself. So you should...
Read more >
[GA4] Custom dimensions and metrics - Analytics Help
If you haven't customized your data collection code, you probably do not need to read this article or use custom dimensions and metrics....
Read more >
Custom dimension not working - Planet Minecraft
I have a custom dimension data pack. If a dimension is not showing up there could be many things wrong. Do you have...
Read more >
Custom dimension show not-set after 2022/02/08 - Issue Tracker
js to log custom dimensions the "field-X" were logged as user-scope dimension. Everything worked perfectly until 2022/02/08. After Feb.08, there are many (not- ......
Read more >
How to Set Up GA4 Custom Dimensions 2022 - MeasureSchool
For instance, you want to track an event that is not available in the ... Let's have a look at how scopes of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found