Skip to content
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

allow setting a custom Redacted.toString #3966

Open
wants to merge 3 commits into
base: next-minor
Choose a base branch
from

Conversation

jessekelly881
Copy link
Contributor

@jessekelly881 jessekelly881 commented Nov 20, 2024

Allow setting a custom string when creating redacted values e.g. "REDACTED_TOKEN" which is logged as:

level=INFO msg="permission granted" user=Perry token=REDACTED_TOKEN

Redacted.make("abc", "REDACTED_TOKEN")

This is useful for keeping tract of redacted values between log statements and is a feature provided by a few other logging libraries.

Copy link

changeset-bot bot commented Nov 20, 2024

🦋 Changeset detected

Latest commit: 76fca8e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 34 packages
Name Type
effect Minor
@effect/cli Major
@effect/cluster-browser Major
@effect/cluster-node Major
@effect/cluster-workflow Major
@effect/cluster Major
@effect/experimental Major
@effect/opentelemetry Major
@effect/platform-browser Major
@effect/platform-bun Major
@effect/platform-node-shared Major
@effect/platform-node Major
@effect/platform Major
@effect/printer-ansi Major
@effect/printer Major
@effect/rpc-http Major
@effect/rpc Major
@effect/sql-clickhouse Major
@effect/sql-d1 Major
@effect/sql-drizzle Major
@effect/sql-kysely Major
@effect/sql-libsql Major
@effect/sql-mssql Major
@effect/sql-mysql2 Major
@effect/sql-pg Major
@effect/sql-sqlite-bun Major
@effect/sql-sqlite-node Major
@effect/sql-sqlite-react-native Major
@effect/sql-sqlite-wasm Major
@effect/sql Major
@effect/typeclass Major
@effect/vitest Major
@effect/ai Major
@effect/ai-openai Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot changed the base branch from main to next-minor November 20, 2024 07:22
@jessekelly881
Copy link
Contributor Author

jessekelly881 commented Nov 20, 2024

A better approach might be to use a ref = {} prop on the Redacted object and allow the other meta data on the Redacted object to be changed directly.

@KhraksMamtsov
Copy link
Contributor

I started working on this idea yesterday) I agree that it is convenient.
but I came to a slightly different implementation.

proto = {
...
  label: "redacted",
  toString() {
    return `<${this.label}>`
  },
  toJSON() {
    return `<${this.label}>`
  },
  [NodeInspectSymbol]() {
    return `<${this.label}>`
  },
...
}
export const make = <T>(
  value: T,
  options?: {
    label?: string | undefined
  } | undefined
): Redacted.Redacted<T> => {
  const redacted = Object.create(proto)
  if (options?.label !== undefined) {
    redacted.label = options?.label
  }
  redactedRegistry.set(redacted, value)
  return redacted
}

Could you please integrate this idea into this places as well?

  • Schema.Redacted/RedactedFromSelf
  • Config.redacted
  • Options.redacted in cli package

@github-actions github-actions bot force-pushed the next-minor branch 4 times, most recently from f45ce22 to 1e52c1b Compare November 20, 2024 18:00
@jessekelly881
Copy link
Contributor Author

jessekelly881 commented Nov 20, 2024

I think having a custom string is much better than forcing the "<>" wrapper. I was looking at the Config.redacted implementation as well and I think it makes more sense to use a Redacted.setString fn which can be mapped inside of Config.map, etc. But as far as I can tell that requires having a .ref prop that actually points to the value rather than using the Redacted instance itself as the ref. But at least for the moment this clashes with the deprecated Secret module.

@github-actions github-actions bot force-pushed the next-minor branch 14 times, most recently from 1a4cddc to 693a803 Compare November 27, 2024 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Discussion Ongoing
Development

Successfully merging this pull request may close these issues.

2 participants