示例#1
0
def _collect_custom_response_headers_attributes(response_headers):
    custom_response_headers_name = get_custom_headers(
        OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE)
    attributes = {}
    for header_name in custom_response_headers_name:
        header_values = response_headers.get(header_name)
        if header_values:
            key = normalise_response_header_name(header_name.lower())
            attributes[key] = [header_values]
    return attributes
示例#2
0
 def test_get_custom_response_header(self):
     custom_headers_to_capture = get_custom_headers(
         OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE)
     self.assertEqual(
         custom_headers_to_capture,
         [
             "content-type",
             "content-length",
             "test-header",
         ],
     )
def collect_custom_request_headers_attributes(environ):
    """Returns custom HTTP request headers which are configured by the user
    from the PEP3333-conforming WSGI environ to be used as span creation attributes as described
    in the specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers"""
    attributes = {}
    custom_request_headers_name = get_custom_headers(
        OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST)
    for header_name in custom_request_headers_name:
        wsgi_env_var = header_name.upper().replace("-", "_")
        header_values = environ.get(f"HTTP_{wsgi_env_var}")
        if header_values:
            key = normalise_request_header_name(header_name)
            attributes[key] = [header_values]
    return attributes
def collect_custom_response_headers_attributes(message):
    """returns custom HTTP response headers to be added into SERVER span as span attributes
    Refer specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers"""
    attributes = {}
    custom_response_headers = get_custom_headers(
        OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE
    )

    for header in custom_response_headers:
        values = asgi_getter.get(message, header)
        if values:
            key = normalise_response_header_name(header)
            attributes.setdefault(key, []).extend(values)

    return attributes
def collect_custom_response_headers_attributes(response_headers):
    """Returns custom HTTP response headers which are configured by the user from the
    PEP3333-conforming WSGI environ as described in the specification
    https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers"""
    attributes = {}
    custom_response_headers_name = get_custom_headers(
        OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE)
    response_headers_dict = {}
    if response_headers:
        for header_name, header_value in response_headers:
            response_headers_dict[header_name.lower()] = header_value

    for header_name in custom_response_headers_name:
        header_values = response_headers_dict.get(header_name.lower())
        if header_values:
            key = normalise_response_header_name(header_name)
            attributes[key] = [header_values]
    return attributes
示例#6
0
 def test_get_custom_request_header(self):
     custom_headers_to_capture = get_custom_headers(
         OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST)
     self.assertEqual(custom_headers_to_capture,
                      ["User-Agent", "Test-Header"])