<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>调试与故障排除 on Dapr 文档库</title><link>https://v1-18.docs.dapr.io/zh-hans/operations/troubleshooting/</link><description>Recent content in 调试与故障排除 on Dapr 文档库</description><generator>Hugo</generator><language>zh-hans</language><atom:link href="https://v1-18.docs.dapr.io/zh-hans/operations/troubleshooting/index.xml" rel="self" type="application/rss+xml"/><item><title>运行 Dapr 时的常见问题</title><link>https://v1-18.docs.dapr.io/zh-hans/operations/troubleshooting/common_issues/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v1-18.docs.dapr.io/zh-hans/operations/troubleshooting/common_issues/</guid><description>&lt;p>本指南涵盖了安装和运行 Dapr 时可能遇到的常见问题。&lt;/p>
&lt;h2 id="安装-dapr-cli-时-dapr-无法连接到-docker">安装 Dapr CLI 时 Dapr 无法连接到 Docker&lt;/h2>
&lt;p>在安装和初始化 Dapr CLI 时，如果在运行 &lt;code>dapr init&lt;/code> 后看到以下错误信息：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>⌛ 正在进行初始化...
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>❌ 无法连接到 Docker。Docker 可能未安装或未运行
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>请通过以下步骤进行排查：&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;a href="https://v1-18.docs.dapr.io/zh-hans/getting-started/install-dapr-selfhost/#step-4-verify-containers-are-running">确保容器正确运行。&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>在 Docker Desktop 中，确认已选择 &lt;strong>允许使用默认 Docker 套接字（需要密码）&lt;/strong> 选项。&lt;/p>
&lt;img src="https://v1-18.docs.dapr.io/images/docker-desktop-setting.png" width=800 style="padding-bottom:15px;">
&lt;/li>
&lt;/ol>
&lt;h2 id="我没有看到-dapr-sidecar-注入到我的-pod-中">我没有看到 Dapr sidecar 注入到我的 pod 中&lt;/h2>
&lt;p>sidecar 未注入到 pod 中可能有多种原因。首先，检查您的部署或 pod YAML 文件，确保在正确的位置有以下注释：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">annotations&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">dapr.io/enabled&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;true&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">dapr.io/app-id&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;nodeapp&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">dapr.io/app-port&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;3000&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="示例部署">示例部署：&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">apiVersion&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">apps/v1&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">kind&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">Deployment&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">nodeapp&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">namespace&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">default&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">labels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">app&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">node&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline">&lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">replicas&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">1&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">selector&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">matchLabels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">app&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">node&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">template&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">metadata&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">labels&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">app&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">node&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">annotations&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">dapr.io/enabled&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;true&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">dapr.io/app-id&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;nodeapp&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">dapr.io/app-port&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;3000&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">spec&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">containers&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">name&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">node&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">image&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">dapriosamples/hello-k8s-node&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">ports&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>- &lt;span style="color:#204a87;font-weight:bold">containerPort&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#0000cf;font-weight:bold">3000&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">imagePullPolicy&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#000">Always&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>在某些情况下，这可能无法正常工作：&lt;/p></description></item><item><title>配置和查看 Dapr 日志</title><link>https://v1-18.docs.dapr.io/zh-hans/operations/troubleshooting/logs-troubleshooting/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v1-18.docs.dapr.io/zh-hans/operations/troubleshooting/logs-troubleshooting/</guid><description>&lt;p>本节将帮助您了解 Dapr 中日志的工作原理，以及如何配置和查看日志。&lt;/p>
&lt;h2 id="概述">概述&lt;/h2>
&lt;p>日志有不同的可配置级别。
以下列出的级别适用于系统组件和 Dapr sidecar 进程/容器：&lt;/p>
&lt;ol>
&lt;li>error&lt;/li>
&lt;li>warn&lt;/li>
&lt;li>info&lt;/li>
&lt;li>debug&lt;/li>
&lt;/ol>
&lt;p>error 级别输出最少，而 debug 级别输出最多。默认级别是 info，它在正常情况下为操作 Dapr 提供了足够的信息。&lt;/p>
&lt;p>要设置输出级别，可以使用 &lt;code>--log-level&lt;/code> 命令行选项。例如：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>./daprd --log-level error
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>./placement --log-level debug
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>这将以 &lt;code>error&lt;/code> 日志级别启动 Dapr 运行时二进制文件，并以 &lt;code>debug&lt;/code> 日志级别启动 Dapr actor 放置服务。&lt;/p>
&lt;h2 id="独立模式下的日志">独立模式下的日志&lt;/h2>
&lt;p>在使用 Dapr CLI 运行应用程序时，可以通过传递 &lt;code>log-level&lt;/code> 参数来设置日志级别：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>dapr run --log-level warn node myapp.js
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>如上所述，每个 Dapr 二进制文件都接受一个 &lt;code>--log-level&lt;/code> 参数。例如，要以警告级别启动放置服务：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>./placement --log-level warn
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="查看独立模式下的日志">查看独立模式下的日志&lt;/h3>
&lt;p>当使用 Dapr CLI 运行 Dapr 时，您的应用程序日志输出和运行时输出将被重定向到同一会话，方便调试。
例如，这是运行 Dapr 时的输出：&lt;/p></description></item><item><title>Dapr API 日志</title><link>https://v1-18.docs.dapr.io/zh-hans/operations/troubleshooting/api-logs-troubleshooting/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v1-18.docs.dapr.io/zh-hans/operations/troubleshooting/api-logs-troubleshooting/</guid><description>&lt;p>API 日志记录可以让您查看应用程序对 Dapr sidecar 的 API 调用情况。这对于监控应用程序行为或进行调试非常有用。您还可以将 Dapr API 日志记录与 Dapr 日志事件结合使用（参见&lt;a href="https://v1-18.docs.dapr.io/zh-hans/operations/troubleshooting/logs-troubleshooting/">配置和查看 Dapr 日志&lt;/a>），以便更好地利用日志记录功能。&lt;/p>
&lt;h2 id="概述">概述&lt;/h2>
&lt;p>API 日志记录默认情况下是禁用的。&lt;/p>
&lt;p>要启用 API 日志记录，可以在启动 &lt;code>daprd&lt;/code> 进程时使用 &lt;code>--enable-api-logging&lt;/code> 命令行选项。例如：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>./daprd --enable-api-logging
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="在自托管模式下配置-api-日志记录">在自托管模式下配置 API 日志记录&lt;/h2>
&lt;p>当使用 Dapr CLI 运行应用程序时，要启用 API 日志记录，请传递 &lt;code>--enable-api-logging&lt;/code> 标志：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>dapr run &lt;span style="color:#4e9a06">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#4e9a06">&lt;/span> --enable-api-logging &lt;span style="color:#4e9a06">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#4e9a06">&lt;/span> -- node myapp.js
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="在自托管模式下查看-api-日志">在自托管模式下查看 API 日志&lt;/h3>
&lt;p>使用 Dapr CLI 运行 Dapr 时，您的应用程序日志输出和 Dapr 运行时日志输出会被重定向到同一会话中，便于调试。&lt;/p>
&lt;p>下面的示例显示了一些 API 日志：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>$ dapr run --enable-api-logging -- node myapp.js
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ℹ️ Starting Dapr with id order-processor on port &lt;span style="color:#0000cf;font-weight:bold">56730&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>✅ You are up and running! Both Dapr and your app logs will appear here.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>.....
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>INFO&lt;span style="color:#ce5c00;font-weight:bold">[&lt;/span>0000&lt;span style="color:#ce5c00;font-weight:bold">]&lt;/span> HTTP API Called &lt;span style="color:#000">app_id&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>order-processor &lt;span style="color:#000">instance&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>mypc &lt;span style="color:#000">method&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&lt;span style="color:#4e9a06">&amp;#34;POST /v1.0/state/mystate&amp;#34;&lt;/span> &lt;span style="color:#000">scope&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>dapr.runtime.http-info &lt;span style="color:#000">type&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>log &lt;span style="color:#000">useragent&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>Go-http-client/1.1 &lt;span style="color:#000">ver&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&lt;span style="color:#000">edge&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ce5c00;font-weight:bold">==&lt;/span> &lt;span style="color:#000">APP&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">==&lt;/span> INFO:root:Saving Order: &lt;span style="color:#ce5c00;font-weight:bold">{&lt;/span>&lt;span style="color:#4e9a06">&amp;#39;orderId&amp;#39;&lt;/span>: &lt;span style="color:#4e9a06">&amp;#39;483&amp;#39;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>INFO&lt;span style="color:#ce5c00;font-weight:bold">[&lt;/span>0000&lt;span style="color:#ce5c00;font-weight:bold">]&lt;/span> HTTP API Called &lt;span style="color:#000">app_id&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>order-processor &lt;span style="color:#000">instance&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>mypc &lt;span style="color:#000">method&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&lt;span style="color:#4e9a06">&amp;#34;GET /v1.0/state/mystate/key123&amp;#34;&lt;/span> &lt;span style="color:#000">scope&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>dapr.runtime.http-info &lt;span style="color:#000">type&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>log &lt;span style="color:#000">useragent&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>Go-http-client/1.1 &lt;span style="color:#000">ver&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&lt;span style="color:#000">edge&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ce5c00;font-weight:bold">==&lt;/span> &lt;span style="color:#000">APP&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">==&lt;/span> INFO:root:Getting Order: &lt;span style="color:#ce5c00;font-weight:bold">{&lt;/span>&lt;span style="color:#4e9a06">&amp;#39;orderId&amp;#39;&lt;/span>: &lt;span style="color:#4e9a06">&amp;#39;483&amp;#39;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>INFO&lt;span style="color:#ce5c00;font-weight:bold">[&lt;/span>0000&lt;span style="color:#ce5c00;font-weight:bold">]&lt;/span> HTTP API Called &lt;span style="color:#000">app_id&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>order-processor &lt;span style="color:#000">instance&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>mypc &lt;span style="color:#000">method&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&lt;span style="color:#4e9a06">&amp;#34;DELETE /v1.0/state/mystate&amp;#34;&lt;/span> &lt;span style="color:#000">scope&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>dapr.runtime.http-info &lt;span style="color:#000">type&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>log &lt;span style="color:#000">useragent&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>Go-http-client/1.1 &lt;span style="color:#000">ver&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&lt;span style="color:#000">edge&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ce5c00;font-weight:bold">==&lt;/span> &lt;span style="color:#000">APP&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">==&lt;/span> INFO:root:Deleted Order: &lt;span style="color:#ce5c00;font-weight:bold">{&lt;/span>&lt;span style="color:#4e9a06">&amp;#39;orderId&amp;#39;&lt;/span>: &lt;span style="color:#4e9a06">&amp;#39;483&amp;#39;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>INFO&lt;span style="color:#ce5c00;font-weight:bold">[&lt;/span>0000&lt;span style="color:#ce5c00;font-weight:bold">]&lt;/span> HTTP API Called &lt;span style="color:#000">app_id&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>order-processor &lt;span style="color:#000">instance&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>mypc &lt;span style="color:#000">method&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>&lt;span style="color:#4e9a06">&amp;#34;PUT /v1.0/metadata/cliPID&amp;#34;&lt;/span> &lt;span style="color:#000">scope&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>dapr.runtime.http-info &lt;span style="color:#000">type&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>log &lt;span style="color:#000">useragent&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>Go-http-client/1.1 &lt;span style="color:#000">ver&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span>edge
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="在-kubernetes-中配置-api-日志记录">在 Kubernetes 中配置 API 日志记录&lt;/h2>
&lt;p>您可以通过在 pod 规范模板中添加以下注释来为 sidecar 启用 API 日志：&lt;/p></description></item><item><title>性能分析与调试</title><link>https://v1-18.docs.dapr.io/zh-hans/operations/troubleshooting/profiling-debugging/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v1-18.docs.dapr.io/zh-hans/operations/troubleshooting/profiling-debugging/</guid><description>&lt;p>在实际应用中，程序可能会出现资源使用高峰的问题。CPU和内存的使用高峰在很多情况下是常见的。&lt;/p>
&lt;p>Dapr 允许用户通过其性能分析服务端点使用 &lt;code>pprof&lt;/code> 启动按需性能分析会话，以检测并发、性能、CPU 和内存使用等问题。&lt;/p>
&lt;h2 id="启用性能分析">启用性能分析&lt;/h2>
&lt;p>Dapr 支持在 Kubernetes 和独立模式下启用性能分析。&lt;/p>
&lt;h3 id="独立模式">独立模式&lt;/h3>
&lt;p>在独立模式下启用性能分析时，可以通过 Dapr CLI 传递 &lt;code>--enable-profiling&lt;/code> 和 &lt;code>--profile-port&lt;/code> 标志：
注意，&lt;code>profile-port&lt;/code> 是可选的，如果未指定，Dapr 会自动选择一个可用端口。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>dapr run --enable-profiling --profile-port &lt;span style="color:#0000cf;font-weight:bold">7777&lt;/span> python myapp.py
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="kubernetes">Kubernetes&lt;/h3>
&lt;p>在 Kubernetes 中启用性能分析，只需在 Dapr 注解的 pod 中添加 &lt;code>dapr.io/enable-profiling&lt;/code> 注解：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yml" data-lang="yml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">annotations&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">dapr.io/enabled&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;true&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">dapr.io/app-id&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;rust-app&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#204a87;font-weight:bold">dapr.io/enable-profiling&lt;/span>&lt;span style="color:#000;font-weight:bold">:&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline"> &lt;/span>&lt;span style="color:#4e9a06">&amp;#34;true&amp;#34;&lt;/span>&lt;span style="color:#f8f8f8;text-decoration:underline">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="调试性能分析会话">调试性能分析会话&lt;/h2>
&lt;p>启用性能分析后，可以启动性能分析会话来调查 Dapr 运行时的情况。&lt;/p>
&lt;h3 id="独立模式-1">独立模式&lt;/h3>
&lt;p>对于独立模式，首先找到需要分析的 Dapr 实例：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>dapr list
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>APP ID DAPR PORT APP PORT COMMAND AGE CREATED PID
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>node-subscriber &lt;span style="color:#0000cf;font-weight:bold">3500&lt;/span> &lt;span style="color:#0000cf;font-weight:bold">3000&lt;/span> node app.js 12s 2019-09-09 15:11.24 &lt;span style="color:#0000cf;font-weight:bold">896&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>获取 DAPR PORT，如果已按上述步骤启用性能分析，现在可以使用 &lt;code>pprof&lt;/code> 对 Dapr 进行分析。
查看上面的 Kubernetes 示例以获取一些有用的命令来分析 Dapr。&lt;/p></description></item></channel></rss>