snowplow / snowbridge

For replicating streams across clouds, accounts and regions
Other
15 stars 7 forks source link

Add metadata to message model for dynamic HTTP headers #293

Closed adatzer closed 7 months ago

adatzer commented 1 year ago

A proposal of a way to enable dynamic HTTP headers (deriving headers from message data) or more generally dynamic target writes (in this PR only HTTP target has become metadata aware).

Metadata becomes a message field that can be populated using a JS transformation (no Lua support at this point).

As an example of a JS transformation script that adds metadata targeting HTTP Request headers:

function main(input) {
  const spData = input.Data;
  const fooCtx = spData['contexts_com_acme_gtm_ss_1'];

  if (fooCtx && fooCtx.length > 0) {
    const previewHeader = fooCtx[0].preview_header;

    if (previewHeader) {
      input.Metadata = {
        Actual: {
          TargetHttpHeaders: {
            "x-gtm-server-preview": [previewHeader]
          }
        },
        AsString: "previewHeader:".concat(previewHeader)
      };
    }
  }

  return input;
}
adatzer commented 7 months ago

Closing in favor of https://github.com/snowplow/snowbridge/pull/308