- 필수 기능
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- 디지털 경험
- 소프트웨어 제공
- 보안
- 로그 관리
- 관리
- 인프라스트럭처
- ci
- containers
- csm
- ndm
- otel_guides
- overview
- slos
- synthetics
- tests
- 워크플로
Synthetic Monitoring allows you to generate variables from JavaScript scripts so you can define custom authentications or encode parameters.
This guide walks you through how to create an HTTP test with an HMAC signature, using variables from script.
Note: There is no standard HMAC authentication, your own HMAC authentication may be slighty different. For instance, it may use a different header name.
Create a Synthetic HTTP test and click Create a Local Variable to add the following variables:
MY_SECRET_KEY
BODY
DATETIME
dd.variable.set('DATETIME', new Date().toISOString())
.Define the URL and the request type for the HTTP test. Then, click Advanced Options > Request Body to add the {{ BODY }}
variable as the request body.
Click Variable From Script to generate the HMAC signature for your HTTP request.
dd.variable.get("<variable_name>")
.dd.variable.set("<variable_name>", <value>)
or dd.variable.setObfuscated("<variable_name>", <value>)
.You also have access to helper functions, such as:
std
library, accessible with std.*
. For example, to call the function encodeHex
defined in <std>/encoding/hex.ts
, use std.encoding.hex.encodeHex
.Note: Some of these APIs are disabled for security reasons.
For example:
Variable from Script
const datetime = new Date().toISOString();
// Set a "date" HTTP header using DATETIME as its value in the UI
dd.variable.set("DATETIME", datetime);
const message = "Hello, World!";
// Use BODY as the request body in the UI
dd.variable.set("BODY", message);
const secretKeyUtf8 = dd.variable.get("MY_SECRET_KEY");
const key = await crypto.subtle.importKey(
"raw",
new TextEncoder().encode(secretKeyUtf8),
{ name: "HMAC", hash: "SHA-256" },
false,
["sign"]
);
const rawSignature = await crypto.subtle.sign(
{ name: "HMAC" },
key,
new TextEncoder().encode(datetime + "." + message)
);
// Set an "authentication" HTTP header using SIGNATURE as its value in the UI
dd.variable.set("SIGNATURE", std.encoding.hex.encodeHex(rawSignature));
// Alternative:
dd.variable.set("SIGNATURE_BASE64", std.encoding.base64.encode(rawSignature));
Use the exported SIGNATURE
variable to build the HTTP request header.
Under the Request Options tab, add a header with Name
set to Authentication
and Value
set to {{ SIGNATURE }}
, and another one with Name
set to Date
and Value
set to {{ DATETIME }}
. You can define a different header such as Authorization
.
Configure the rest of your HTTP test, and click Create to save.
Additional helpful documentation, links, and articles: