Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

散らばったトレースを繋げる技術

Kazuki Obata
November 29, 2024
380

 散らばったトレースを繋げる技術

Kazuki Obata

November 29, 2024
Tweet

Transcript

  1. © 2024 Wantedly, Inc. ࿩͍ͨ͜͠ͱ - ΦϒβʔόϏϦςΟͷߏ੒ཁૉʮτϨʔεʯ - όϥόϥʹͳͬͯ͠·͏ͱࠔΔ -

    ໰୊ͱͳΔՕॴɾϙΠϯτΛղઆ - εύϯΛܨ͛ͯτϨʔεʹ͢Δํ๏Λ঺հ - ίʔυϕʔεͰղઆ - ֶͼ
  2. © 2024 Wantedly, Inc. APM ͰτϨʔεܨ͕Βͳ͍... - ىͬͨ͜͜ͱ - OpenCensus

    ͱ dd-trace ͷτϨʔε͕όϥόϥ - ܭ૷ͨ͠τϨʔεͱ Redis ͷτϨʔε͕όϥόϥ - ༗ޮͳ৘ใ͕ͺͬͱݟΕͳ͍☹ - Ͳ͕͜໰୊͔ɺϘτϧωοΫʹͳ͍ͬͯΔ͔Ұ໨Ͱ෼͔Βͳ͍ - εύϯ͕όϥόϥͰௐࠪͮ͠Β͍ https://docs.datadoghq.com/ja/tracing/glossary/
  3. © 2024 Wantedly, Inc. τϨʔείϯςΩετΛ఻೻͢Δ - τϨʔείϯςΩετͱ͸ - τϨʔεIDɾεύϯIDɾ਌εύϯID Λ࣋ͬͨσʔλߏ଄

    - ಉ͡τϨʔείϯςΩετ͔Βੜ੒͞Εͨεύϯ͸ಉ͡τϨʔεʹଐ͢Δ - ਌ࢠؔ܎΋ҡ࣋͞ΕΔ - ໰୊ͷݪҼ - TraceIDͷϑΥʔϚοτ͕ҟͳΔ - τϨʔείϯςΩετΛඞཁͳՕॴͰ࢖͍͑ͯͳ͍ - ผʑͷτϨʔείϯςΩετΛ࢖͍ͬͯͨ
  4. © 2024 Wantedly, Inc. ͭͳ͛ํ 1. OpenCensus ͱ ddtrace ͷτϨʔεΛܨ͛Δ

    Go (dd-trace-go) ͷྫ // ϑΥʔϚοτΛ੔͑Δ carrier := tracer.TextMapCarrier{ tracer.DefaultTraceIDHeader: strconv.FormatUint(binary.BigEndian.Uint64(traceID[8:]), 10), tracer.DefaultParentIDHeader: strconv.FormatUint(binary.BigEndian.Uint64(spanID[:]), 10), } // ίϯςΩετͷੜ੒ sctx, _ := tracer.Extract(carrier) // εύϯͷੜ੒ span, ctx := tracer.StartSpanFromContext(ctx, "op1", tracer.ChildOf(sctx)) // ctx Λ࢖ͬͯଞͷεύϯΛੜ੒ span, ctx := tracer.StartSpanFromContext(ctx, "op2", tracer.ChildOf(sctx))
  5. © 2024 Wantedly, Inc. ͭͳ͛ํ 2. Redis ͷτϨʔεΛܨ͛Δ Redigo ͷྫ

    // Redis ΫϥΠΞϯτͷ Wrapper Λ࢖͏ pool := &redis.Pool{ Dial: func() (redis.Conn, error) { return redigotrace.Dial("tcp", "127.0.0.1:6379", redigotrace.WithServiceName("my-redis-backend"), ) }, } // ίϯςΩετΛ࢖͍ճ͢ c.Do("SET", "food", "cheese", ctx) https://pkg.go.dev/gopkg.in/DataDog/[email protected]/contrib/gomodule/redigo
  6. © 2024 Wantedly, Inc. ·ͱΊ - ཁ͢ΔʹτϨʔείϯςΩετΛ࢖͍·Θͤ͹ྑ͍ - ಉ͡τϨʔεIDΛ࢖͏ -

    εύϯͷ਌ࢠؔ܎ - ܨ͕ͬͯͳ͍ͱ͖͸τϨʔεIDΛ֬ೝ - τϨʔεID͕ҟͳ͍ͬͯͳ͍͔ - e.g. ϑΥʔϚοτ͕ҧ͏ɺencode/decode ͕ؒҧ͍ͬͯΔ - τϨʔείϯςΩετͷ఻೻͕Ͱ͖͍ͯΔ͔ - e.g. ctx ͷ౉͍ͯ͠ͳ͍ɺ࢖͍ͬͯͳ͍ ࢄΒ͹ͬͨτϨʔεΛܨ͛Δ