Skip to content

Commit 6b04331

Browse files
committed
fix: keep registry identity in sync after _setIdentity
1 parent 8957026 commit 6b04331

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

packages/client/lib/client/identity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export enum ClientRole {
2929
*/
3030
export interface ClientIdentity {
3131
readonly id: string;
32-
readonly role: ClientRole;
33-
readonly parentId?: string;
32+
role: ClientRole;
33+
parentId?: string;
3434
}
3535

3636
/**

packages/client/lib/client/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,11 @@ export default class RedisClient<
481481
* Sets the client identity. Used by pool/cluster/sentinel when creating child clients.
482482
*/
483483
_setIdentity(role: ClientRole, parentId?: string): void {
484-
this._self.#clientIdentity = {
485-
...this._self.#clientIdentity,
486-
role,
487-
parentId
488-
};
484+
this._self.#clientIdentity.role = role;
485+
486+
if (parentId) {
487+
this._self.#clientIdentity.parentId = parentId;
488+
}
489489
}
490490

491491
/**

packages/client/lib/opentelemetry/client-registry.spec.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe("ClientRegistry Unit Tests", () => {
126126

127127
it("should handle unix socket clients", () => {
128128
ClientRegistry.init();
129-
129+
130130
createClient({
131131
socket: {
132132
path: "/tmp/redis.sock",
@@ -148,6 +148,25 @@ describe("ClientRegistry Unit Tests", () => {
148148
assert.strictEqual(attributes.db, 0);
149149
assert.strictEqual(attributes.clientId, handle.identity.id);
150150
});
151+
152+
it("should reflect identity updates after _setIdentity", () => {
153+
ClientRegistry.init();
154+
155+
const client = createClient();
156+
const originalId = client._clientId;
157+
158+
client._setIdentity(ClientRole.POOL_MEMBER, "pool-1");
159+
160+
const handle = ClientRegistry.instance.getById(originalId);
161+
assert.ok(handle);
162+
assert.strictEqual(handle.identity.id, originalId);
163+
assert.strictEqual(handle.identity.role, ClientRole.POOL_MEMBER);
164+
assert.strictEqual(handle.identity.parentId, "pool-1");
165+
166+
const attributes = handle.getAttributes();
167+
assert.strictEqual(attributes.clientId, originalId);
168+
assert.strictEqual(attributes.parentId, "pool-1");
169+
});
151170
});
152171

153172
describe("ClientRegistry E2E", function () {

0 commit comments

Comments
 (0)