Title: Context properties of custom Channel ignored in LoggingHandler · Issue #104 · microsoft/ApplicationInsights-Python · GitHub
Open Graph Title: Context properties of custom Channel ignored in LoggingHandler · Issue #104 · microsoft/ApplicationInsights-Python
X Title: Context properties of custom Channel ignored in LoggingHandler · Issue #104 · microsoft/ApplicationInsights-Python
Description: I'm trying to set up a LoggingHandler with a few context properties but this is impossible currently: import logging from applicationinsights import channel from applicationinsights.logging import LoggingHandler channel = channel.Telemet...
Open Graph Description: I'm trying to set up a LoggingHandler with a few context properties but this is impossible currently: import logging from applicationinsights import channel from applicationinsights.logging import ...
X Description: I'm trying to set up a LoggingHandler with a few context properties but this is impossible currently: import logging from applicationinsights import channel from applicationinsights.logging imp...
Opengraph URL: https://github.com/microsoft/ApplicationInsights-Python/issues/104
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Context properties of custom Channel ignored in LoggingHandler","articleBody":"I'm trying to set up a LoggingHandler with a few context properties but this is impossible currently:\r\n```py\r\nimport logging\r\nfrom applicationinsights import channel\r\nfrom applicationinsights.logging import LoggingHandler\r\n\r\nchannel = channel.TelemetryChannel()\r\nchannel.context.properties['foo'] = 'bar'\r\nhandler = LoggingHandler(key, telemetry_channel=channel)\r\nlogging.basicConfig(handlers=[handler], format='%(message)s', level=logging.DEBUG)\r\n\r\nlogging.info(\"foo\") # trace does not include foo property\r\nlogging.shutdown()\r\n```\r\n\r\nThe reason this is not working is that LoggingHandler constructs a new TelemetryClient instance which then ignores the existing context from the passed channel object:\r\n```py\r\nclass TelemetryClient(object):\r\n def __init__(self, instrumentation_key, telemetry_channel=None):\r\n ...\r\n self._context = channel.TelemetryContext()\r\n self._context.instrumentation_key = instrumentation_key\r\n self._channel = telemetry_channel or channel.TelemetryChannel()\r\n\r\n @property\r\n def context(self):\r\n return self._context\r\n```\r\n\r\nShouldn't this be instead:\r\n```py\r\nclass TelemetryClient(object):\r\n def __init__(self, instrumentation_key, telemetry_channel=None):\r\n self._channel = telemetry_channel or channel.TelemetryChannel()\r\n self.context.instrumentation_key = instrumentation_key\r\n\r\n @property\r\n def context(self):\r\n return self._channel.context\r\n```\r\n?","author":{"url":"https://github.com/letmaik","@type":"Person","name":"letmaik"},"datePublished":"2018-06-26T16:21:11Z","url":"https://github.com/microsoft/ApplicationInsights-Python/issues/104"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b088d92c-6baa-755c-bef7-96529cfd5475 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D8EA:2EA7B6:777667:9E9996:6B04CB38 |
| html-safe-nonce | d066dea146c6e292da780020f89a92fc672ce5d6130c06ee94796cabc4c0a91d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOEVBOjJFQTdCNjo3Nzc2Njc6OUU5OTk2OjZCMDRDQjM4IiwidmlzaXRvcl9pZCI6Ijc4Mzc1MjQzNjg3MDMxNDY4MDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 77a8a8c8686d48165a85a11ca7603e97082ec0bc97a9342bcefcc7d8bc2a80c1 |
| hovercard-subject-tag | issue:335897138 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/ApplicationInsights-Python/104/issue_layout |
| twitter:image | https://opengraph.githubassets.com/148b159d0c15b69d104228a4c036951f623f40f3c29aea354ad80ca4345cf284/microsoft/ApplicationInsights-Python/issues/104 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/148b159d0c15b69d104228a4c036951f623f40f3c29aea354ad80ca4345cf284/microsoft/ApplicationInsights-Python/issues/104 |
| og:image:alt | I'm trying to set up a LoggingHandler with a few context properties but this is impossible currently: import logging from applicationinsights import channel from applicationinsights.logging import ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | letmaik |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27ed421e5c2dac040a37529b5b9191edcc4a3de70521471e81fb4b4d9dc2aa7d |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/ApplicationInsights-Python git https://github.com/microsoft/ApplicationInsights-Python.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 26877260 |
| octolytics-dimension-repository_nwo | microsoft/ApplicationInsights-Python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 26877260 |
| octolytics-dimension-repository_network_root_nwo | microsoft/ApplicationInsights-Python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 63dc19014c621c67306d7899c04c78dcd0d95803 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width