Skip to content

Conversation

@asein-sinch
Copy link
Collaborator

@asein-sinch asein-sinch commented Dec 2, 2025

How to enable debug logs:

import winston from 'winston';
const winstonLogger = winston.createLogger({
  level: 'debug',
  transports: [new winston.transports.Console()],
  format: winston.format.logstash(),
});

new SinchClient({ projectId, keyId, keySecret, logger:  winstonLogger});

Debug logs:

[Sinch SDK][Debug][AvailableRegionsApi][ListAvailableRegions][401]
HTTP method: GET
URL: https://numbers.api.sinch.com/v1/projects/37b62a7b-0177-429a-bb0b-e10f848de0b8/availableRegions?types=LOCAL&types=MOBILE
Response Headers:  Headers {
  [Symbol(map)]: [Object: null prototype] {
    'www-authenticate': [
      'Bearer error="invalid_token", error_description="Jwt expired at 2023-10-02T14:57:08Z", error_uri="https://tools.ietf.org/html/rfc6750#section-3.1"'
    ],
    'cache-control': [ 'no-cache, no-store, max-age=0, must-revalidate' ],
    pragma: [ 'no-cache' ],
    expires: [ '0' ],
    'x-content-type-options': [ 'nosniff' ],
    'strict-transport-security': [ 'max-age=31536000 ; includeSubDomains' ],
    'x-frame-options': [ 'DENY' ],
    'x-xss-protection': [ '0' ],
    'referrer-policy': [ 'no-referrer' ],
    'x-envoy-upstream-service-time': [ '2' ],
    date: [ 'Tue, 02 Dec 2025 22:25:38 GMT' ],
    server: [ 'istio-envoy' ],
    connection: [ 'close' ],
    'content-length': [ '0' ]
  }
}


private debug(context: ResponsePluginContext) {
if (context.requestOptions.logHeadersOnError && !context.response?.ok) {
console.debug(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should think about supporting also for this SDK a logger interface.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added logger

context.response?.headers,
if (!context.response?.ok) {
this.logger.debug(
`[Sinch SDK][Debug][${context.apiName}][${context.operationId}][${context.response?.status}]\nHTTP method: ${context.requestOptions.method}\nURL: ${context.url}\nResponse Headers: ${this.formatHeaders(context.response?.headers)}`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about having the logger itself adding these formatting information ?

  • this.logger: will know "it is" SDK -> it will add it when emitting log
  • this.logger.debug: logger.debug function will know it is debug level then it will be added when emitting log

PROS:

  • all calls to logger will be prefixed by same ... prefix
  • all calls to logger./debug/info/..will have same prefix regarding log level
  • all logs will have same pattern [Sinch SDK][level] and no human error to forgot them services will call logger function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@asein-sinch asein-sinch requested a review from JPPortier December 3, 2025 18:35

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️
May be adding some unit tests to ensure proper/format and log level.
Not sure we want to go to this direction for console logger and this PR, but other logging frameworks (e.g.: winston pointed by PR comment) are enabling to configure log level to not flood logs output/destination

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.

3 participants