Skip to content

Commit

Permalink
chore: replace deprecated substr() with substring() (#2553)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Nov 27, 2024
1 parent e7cc441 commit 2f5d1de
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,5 +392,5 @@ function wrapPromise<T>(
}

function truncateQuery(query: unknown, maxQueryLength: number) {
return String(query).substr(0, maxQueryLength);
return String(query).substring(0, maxQueryLength);
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ describe('CassandraDriverInstrumentation', () => {
it('truncates long queries', async () => {
const query = 'select userid, count from ot.test';
await client.execute(query);
assertSingleSpan('cassandra-driver.execute', query.substr(0, 25));
assertSingleSpan('cassandra-driver.execute', query.substring(0, 25));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class FastifyInstrumentation extends InstrumentationBase<FastifyInstrumen
anyRequest.routeOptions?.handler || anyRequest.context?.handler;

const handlerName = handler?.name.startsWith('bound ')
? handler.name.substr(6)
? handler.name.substring(6)
: handler?.name;
const spanName = `${FastifyNames.REQUEST_HANDLER} - ${
handlerName || this.pluginName || ANONYMOUS_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const limitLength = (str: string, maxLength: number) => {
0 < maxLength &&
maxLength < str.length
) {
return str.substr(0, maxLength) + '..';
return str.substring(0, maxLength) + '..';
}
return str;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('Knex instrumentation', () => {
const [span] = memoryExporter.getFinishedSpans();
const limitedStatement = span?.attributes?.['db.statement'] as string;
assert.strictEqual(limitedStatement.length, 52);
assert.ok(statement.startsWith(limitedStatement.substr(0, 50)));
assert.ok(statement.startsWith(limitedStatement.substring(0, 50)));
});

it('should catch errors', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class OTTracePropagator implements TextMapPropagator {
const spanContext = trace.getSpan(context)?.spanContext();
if (!spanContext || !isSpanContextValid(spanContext)) return;

setter.set(carrier, OT_TRACE_ID_HEADER, spanContext.traceId.substr(16));
setter.set(carrier, OT_TRACE_ID_HEADER, spanContext.traceId.substring(16));
setter.set(carrier, OT_SPAN_ID_HEADER, spanContext.spanId);
setter.set(
carrier,
Expand Down Expand Up @@ -110,7 +110,7 @@ export class OTTracePropagator implements TextMapPropagator {
getter.keys(carrier).forEach(k => {
if (!k.startsWith(OT_BAGGAGE_PREFIX)) return;
const value = readHeader(carrier, getter, k);
baggage = baggage.setEntry(k.substr(OT_BAGGAGE_PREFIX.length), {
baggage = baggage.setEntry(k.substring(OT_BAGGAGE_PREFIX.length), {
value,
});
});
Expand Down

0 comments on commit 2f5d1de

Please sign in to comment.