Skip to content

feat(core): add http debug utility to core/protocols #1547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Mar 18, 2025

PR adds a function addHttpDebugLogMiddleware exported from @smithy/core/debug, a standalone submodule that will not affect the size of existing applications.

The configurable function attaches middleware to a client or command middleware stack and logs HTTP messages.
The level of detail can be configured, and XML and JSON formatting are supported.

import { DynamoDB } from "@aws-sdk/client-dynamodb";
import { addHttpDebugLogMiddleware } from "@smithy/core/debug";

const client = new DynamoDB();

// 2nd parameter is options. It can be an object or a string with word-matches.
// See PR diff for details.
addHttpDebugLogMiddleware(client.middlewareStack, "line headers formatted");

await client
  .describeTable({
    TableName: "test",
  })
  .catch(() => {});

output:

200 POST DynamoDBClient DescribeTableCommand
    https://....ddb.us-west-2.amazonaws.com/
    >> Request Headers: {
      "content-type": "application/x-amz-json-1.0",
      "x-amz-target": "DynamoDB_20120810.DescribeTable",
      "content-length": "...",
      "x-amz-user-agent": "aws-sdk-js/3.767.0",
      "user-agent": "aws-sdk-js/3.767.0 ua/2.1 os/darwin#24.3.0 lang/js md/nodejs#20.18.1 api/dynamodb#3.767.0 m/E,O,P,T,i,o",
      "host": ".....ddb.us-west-2.amazonaws.com",
      "amz-sdk-invocation-id": "a0aa9a03-72a6-4b6f-8587-....",
      "amz-sdk-request": "attempt=1; max=3",
      "x-amz-date": "20250318T201446Z",
      "x-amz-security-token": "***",
      "x-amz-content-sha256": "....",
      "authorization": "AWS4-HMAC-SHA256 Credential=***/20250318/us-west-2/dynamodb/aws4_request, SignedHeaders=amz-sdk-invocation-id;amz-sdk-request;content-length;content-type;host;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-target;x-amz-user-agent, Signature=***"
    }
    << Response Headers: {
      "server": "Server",
      "date": "Tue, 18 Mar 2025 20:14:46 GMT",
      "content-type": "application/x-amz-json-1.0",
      "content-length": "....",
      "connection": "keep-alive",
      "x-amzn-requestid": "....",
      "x-amz-crc32": "...."
    }
    ====== Response Body Start ======
    {
      "Table": {
        "AttributeDefinitions": [
          ...
        ],
        "BillingModeSummary": {
          ...
        },
        ... 
      }
    }
    ====== Response Body End ======

@kuhe kuhe requested a review from a team as a code owner March 18, 2025 20:13
@kuhe kuhe force-pushed the feat/http-debug branch 7 times, most recently from b3c5c76 to 527a339 Compare March 19, 2025 16:08
@kuhe kuhe force-pushed the feat/http-debug branch from 527a339 to e6edffe Compare March 19, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants