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

fix(instrumentation-redis-4): avoid diag.error spam when configured client URL is the empty string #2399

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function removeCredentialsFromDBConnectionStringAttribute(
diag: DiagLogger,
url?: unknown
): string | undefined {
if (typeof url !== 'string') {
if (typeof url !== 'string' || !url) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { diag, DiagLogLevel } from '@opentelemetry/api';
import {
getTestSpans,
registerInstrumentationTesting,
Expand Down Expand Up @@ -288,6 +290,36 @@ describe('redis@^4.0.0', () => {
expectAttributeConnString
);
});

it('with empty string for client URL, there is no crash and no diag.error', async () => {
// Note: This messily leaves the diag logger set for other tests.
const diagErrors = [] as any;
diag.setLogger(
{
verbose() {},
debug() {},
info() {},
warn() {},
error(...args) {
diagErrors.push(args);
},
},
DiagLogLevel.WARN
);

const newClient = createClient({ url: '' });
try {
await newClient.connect();
} catch (_err) {
// Ignore. If the test Redis is not at the default port we expect this
// to error.
}
await newClient.disconnect();

const [span] = getTestSpans();
assert.strictEqual(span.name, 'redis-connect');
assert.strictEqual(diagErrors.length, 0, "no diag.error's");
});
});

describe('multi (transactions) commands', () => {
Expand Down
Loading