DJANGO OPENCENSUS url 请求数据中的字段太长
DJANGO OPENCENSUS url field in request data too long
我也遇到了与 this question since adding App Insights to my application. It may be related to 类似的问题,但它们都与 App Insights 没有直接关系,也没有解决方案。
这是 django 的错误-tasks.log
Data drop 400: 100: Field 'url' on type 'RequestData' is too long. Expected: 2048 characters, Actual: 3701 {'iKey': <uuid>, 'tags': {'ai.cloud.role': 'manage.py', 'ai.cloud.roleInstance': <instance>, 'ai.device.id': <device>, 'ai.device.locale': 'en_US', 'ai.device.osVersion': '#1 SMP Tue Aug 25 17:23:54 UTC 2020', 'ai.device.type': 'Other', 'ai.internal.sdkVersion': 'py3.6.12:oc0.7.11:ext1.0.4', 'ai.operation.id': 'fcbe18bf6ca9036aa4546af171f3e877', 'ai.operation.name': 'GET /<my_url>/'}, 'time': '2020-12-15T17:58:36.498868Z', 'name': 'Microsoft.ApplicationInsights.Request', 'data': {'baseData': {'id': '116a0658b513bdb9', 'duration': '0.00:00:00.096', 'responseCode': '200', 'success': True, 'properties': {'request.name': 'GET /<my_url>/', 'request.url': 'https://<my host>/<my_url>/?<my very long query string>', 'django.user.id': '90', 'django.user.name': '100044505'}, 'ver': 2, 'name': 'GET /<my_url>/', 'url': 'https://<my host>/<my_url>/?<my very long query string>', 'source': None, 'measurements': None}, 'baseType': 'RequestData'}, 'ver': 1, 'sampleRate': None, 'seq': None, 'flags': None}.
我们也在日志中看到这种重复。
Queue is full. Dropping telemetry.
Queue is full. Dropping telemetry.
Queue is full. Dropping telemetry.
Queue is full. Dropping telemetry.
Queue is full. Dropping telemetry.
Queue is full. Dropping telemetry.
我可以重写应用程序以使用更短的查询,但这似乎是错误的答案。有没有办法配置 django 以支持长 URL。
缓冲区无法更改,但您可以使用过滤器限制 URL 的大小。为了自定义导出的跟踪,必须单独实例化。
def shorten_url(envelope):
if 25 < len(envelope.data.baseData.url):
envelope.data.baseData["url"] = envelope.data.baseData.url[:25]+"..."
return True
from opencensus.ext.azure.trace_exporter import AzureExporter
exporter = AzureExporter(service_name='mysite')
exporter.add_telemetry_processor(shorten_url)
OPENCENSUS = {
'TRACE': {
'SAMPLER': 'opencensus.trace.samplers.ProbabilitySampler(rate=1)',
'EXPORTER': exporter
#Assumes Environmental Variable 'APPINSIGHTS_INSTRUMENTATIONKEY'
}
}
完整的工作示例:
https://github.com/Gamecock/Django-appinsights-example
我也遇到了与 this question since adding App Insights to my application. It may be related to
这是 django 的错误-tasks.log
Data drop 400: 100: Field 'url' on type 'RequestData' is too long. Expected: 2048 characters, Actual: 3701 {'iKey': <uuid>, 'tags': {'ai.cloud.role': 'manage.py', 'ai.cloud.roleInstance': <instance>, 'ai.device.id': <device>, 'ai.device.locale': 'en_US', 'ai.device.osVersion': '#1 SMP Tue Aug 25 17:23:54 UTC 2020', 'ai.device.type': 'Other', 'ai.internal.sdkVersion': 'py3.6.12:oc0.7.11:ext1.0.4', 'ai.operation.id': 'fcbe18bf6ca9036aa4546af171f3e877', 'ai.operation.name': 'GET /<my_url>/'}, 'time': '2020-12-15T17:58:36.498868Z', 'name': 'Microsoft.ApplicationInsights.Request', 'data': {'baseData': {'id': '116a0658b513bdb9', 'duration': '0.00:00:00.096', 'responseCode': '200', 'success': True, 'properties': {'request.name': 'GET /<my_url>/', 'request.url': 'https://<my host>/<my_url>/?<my very long query string>', 'django.user.id': '90', 'django.user.name': '100044505'}, 'ver': 2, 'name': 'GET /<my_url>/', 'url': 'https://<my host>/<my_url>/?<my very long query string>', 'source': None, 'measurements': None}, 'baseType': 'RequestData'}, 'ver': 1, 'sampleRate': None, 'seq': None, 'flags': None}.
我们也在日志中看到这种重复。
Queue is full. Dropping telemetry.
Queue is full. Dropping telemetry.
Queue is full. Dropping telemetry.
Queue is full. Dropping telemetry.
Queue is full. Dropping telemetry.
Queue is full. Dropping telemetry.
我可以重写应用程序以使用更短的查询,但这似乎是错误的答案。有没有办法配置 django 以支持长 URL。
缓冲区无法更改,但您可以使用过滤器限制 URL 的大小。为了自定义导出的跟踪,必须单独实例化。
def shorten_url(envelope):
if 25 < len(envelope.data.baseData.url):
envelope.data.baseData["url"] = envelope.data.baseData.url[:25]+"..."
return True
from opencensus.ext.azure.trace_exporter import AzureExporter
exporter = AzureExporter(service_name='mysite')
exporter.add_telemetry_processor(shorten_url)
OPENCENSUS = {
'TRACE': {
'SAMPLER': 'opencensus.trace.samplers.ProbabilitySampler(rate=1)',
'EXPORTER': exporter
#Assumes Environmental Variable 'APPINSIGHTS_INSTRUMENTATIONKEY'
}
}
完整的工作示例: https://github.com/Gamecock/Django-appinsights-example