te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>c# - What's the correct format for the Request-Id header, so that's recognized by the Azure Monitor OpenTelemetr
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - What's the correct format for the Request-Id header, so that's recognized by the Azure Monitor OpenTelemetr

programmeradmin2浏览0评论

I want to send a Request-Id header, so that it's used by the Azure Monitor OpenTelemetry package for the operation ID.

I have made several attempts, including:

'Request-Id: |9e74f0e5-efc4-41b5-86d1-3524a43bd891.'

and

'Correlation-Context: Id=9e74f0e5-efc4-41b5-86d1-3524a43bd891'

However, none of these is recognized by ASP.NET Core.

The LegacyPropagator : DistributedContextPropagator in System.Diagnostics is responsible for parsing the trace ID from the Request-Id header with:

getter(carrier, RequestId, out traceId, out _);

I don't understand from this code how I supply the trace ID via the Request-Id header.

The correlation HTTP protocol, also called Request-Id, is being deprecated. This protocol defines two headers:

  • Request-Id: Carries the globally unique ID of the call.
  • Correlation-Context: Carries the name-value pairs collection of the distributed trace properties.

I want to send a Request-Id header, so that it's used by the Azure Monitor OpenTelemetry package for the operation ID.

I have made several attempts, including:

'Request-Id: |9e74f0e5-efc4-41b5-86d1-3524a43bd891.'

and

'Correlation-Context: Id=9e74f0e5-efc4-41b5-86d1-3524a43bd891'

However, none of these is recognized by ASP.NET Core.

The LegacyPropagator : DistributedContextPropagator in System.Diagnostics is responsible for parsing the trace ID from the Request-Id header with:

getter(carrier, RequestId, out traceId, out _);

I don't understand from this code how I supply the trace ID via the Request-Id header.

The correlation HTTP protocol, also called Request-Id, is being deprecated. This protocol defines two headers:

  • Request-Id: Carries the globally unique ID of the call.
  • Correlation-Context: Carries the name-value pairs collection of the distributed trace properties.

https://learn.microsoft/en-us/azure/azure-monitor/app/distributed-trace-data#correlation-headers-using-w3c-tracecontext

Share Improve this question edited yesterday Suresh Chikkam 3,3802 gold badges4 silver badges12 bronze badges Recognized by Microsoft Azure Collective asked 2 days ago ShuzhengShuzheng 13.9k29 gold badges115 silver badges226 bronze badges 8
  • Have you tried using W3C Trace Context (traceparent) - traceparent: 00-<trace-id>-<span-id>-01 – Suresh Chikkam Commented 2 days ago
  • @SureshChikkam, Yes, but I want to use Request-Id instead – Shuzheng Commented 2 days ago
  • Trace ID must adhere to the hierarchical request ID format - |<trace-id>.<span-id>. – Suresh Chikkam Commented 2 days ago
  • Root ID: |9e74f0e5efc441b586d13524a43bd891. , Hierarchical ID with span: |9e74f0e5efc441b586d13524a43bd891.1d2f3e4g5h6i7j8k. – Suresh Chikkam Commented 2 days ago
  • If you change all your request IDs to the right format, then that might work, but you won't get tracing since it requires the W3C trace context which contains more information than just a request id. – MartinDotNet Commented 2 days ago
 |  Show 3 more comments

1 Answer 1

Reset to default 0

To make the Request-Id header work properly, you need to follow the hierarchical request ID format specified by the deprecated correlation protocol. Specifically,

Format of Request-Id: |<root-id>.<local-id1>.<local-id2>.

  • Root Request ID : Request-Id: |9e74f0e5efc441b586d13524a43bd891.

  • Hierarchical Request ID with Span : Request-Id: |9e74f0e5efc441b586d13524a43bd891.1d2f3e4g5h6i7j8k.

| (vertical bar), . (dot), and _ (underscore) are reserved for hierarchical structure. These characters cannot be part of node values. hyphen - is allowed in node values.

This above format checks compatibility with the LegacyPropagator, which recognizes and parses the Request-Id header.

If you are only aiming to pass a custom trace ID for backward compatibility with legacy systems, the Request-Id format described above will suffice. But for full tracing capabilities, transitioning to the W3C Trace Context is recommended.

Here is the code for creating and managing Request-Id headers.

public static string GenerateRequestId(string traceId = null, string spanId = null)
{
    // Use provided traceId, or generate a new one (UUID without hyphens)
    var rootId = traceId ?? Guid.NewGuid().ToString("N");

    // Generate a unique local ID (span)
    var localId = spanId ?? Guid.NewGuid().ToString("N").Substring(0, 8); // Optional short span

    // Combine root and local IDs into a hierarchical Request-Id
    return $"|{rootId}.{localId}.";
}

You can also parse incoming headers and adjust their format.

public static string MapTraceparentToRequestId(string traceparent)
{
    // Example traceparent: "00-9e74f0e5efc441b586d13524a43bd891-1b2f3c4d5e6f7g8h-01"
    var parts = traceparent.Split('-');
    if (parts.Length < 2) return null;

    var traceId = parts[1]; // Extract <trace-id>
    var spanId = parts[2];  // Extract <span-id>
    return $"|{traceId}.{spanId}.";
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论