Hey everyone! I’m working on a React app and I want to send logs to a collector using OpenTelemetry. The thing is I’m setting my token when the app starts but it only lasts for 5 minutes. I need to find a way to update it smoothly.
Here’s what I’ve got so far:
// Sending logs
logHandler.send({
level: severity,
content: log,
metadata: {
...extraInfo,
logTime: new Date().toISOString(),
},
});
// Setting up the logger
const logHandler = new LogHandler({ resourceInfo });
const logSender = new CustomLogSender({ endpoint: `${LOG_SERVER}/api`, authHeaders });
logHandler.useProcessor(new LogBatchProcessor(logSender));
const logger = logHandler.createLogger('main-logger');
export { logger };
// Trying to update the token
class DynamicLogSender extends CustomLogSender {
constructor(endpoint) {
super({ endpoint });
}
transmit(data, onComplete, onFail) {
this.authHeaders = {
Token: window.currentToken ?? '',
MaxConcurrency: '1',
}
super.transmit(data, onComplete, onFail);
}
}
I tried to override the send method but I’m not sure if it’s the best approach. Any ideas on how to handle this token update smoothly? Thanks in advance!